2. Outline
What is a view?
Restrictions when using views
Syntax
Sample CREATE VIEW statement
Advantages and disadvantages of using
views
3. What is a view?
Virtual table based on the result-set of an
SQL statement
The fields in a view are fields from one or
more real tables in the database
4. Restrictions on views
The SELECT statement cannot contain a
subquery
The SELECT statement cannot refer to
system or user variables
Any table or view referred to in the
definition must exist
5. Restrictions on views
A temporary VIEW cannot be created
A VIEW cannot be associated with a trigger
7. Example: View
CREATE OR REPLACE VIEW `view_track_details`
AS
SELECT TRK.id, TRK.title AS 'track_title',
TRK.rating, TRK.len AS 'length',
TRK.count AS 'play_count', ALB.title AS
'album_title', ART.`name` AS 'artist',
GNR.`name` AS 'genre'
FROM track TRK
JOIN album ALB ON TRK.album_id = ALB.id
JOIN artist ART ON ALB.artist_id = ART.id
JOIN genre GNR ON TRK.genre_id = GNR.id;
8. “Avie w is no thing m o re than a pse udo -table do ing
the wo rk o f a de fine d q ue ry. ”
9. Advantages and disadvantages
Advantages:
Easily maintainable pseudo-tables of data
Added level of security by not exposing the
table structure of the application
Disadvantages:
Performance hit
10. Advantages and disadvantages
Advantages:
Easily maintainable pseudo-tables of data
Added level of security by not exposing the
table structure of the application
Disadvantages:
Performance hit