MySQL Views

992 views

Published on

MySQL Views
- Definition
- Restrictions
- Syntax
- Example
- Advantages and disadvantages

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
992
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
25
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

MySQL Views

  1. 1. MySQL Views Reggie Niccolo Santos UP ITDC
  2. 2. Outline  What is a view?  Restrictions when using views  Syntax  Sample CREATE VIEW statement  Advantages and disadvantages of using views
  3. 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. 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. 5. Restrictions on views  A temporary VIEW cannot be created  A VIEW cannot be associated with a trigger
  6. 6. Syntax: CREATE VIEW CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = { user | CURRENT_USER }] [SQL SECURITY { DEFINER | INVOKER }] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] CHECK OPTION]
  7. 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. 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. 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. 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
  11. 11. References  http://www.w3schools.com/sql/sql_view.asp  Http://net.tutsplus.com/tutorials/databases/introdu  Http://zetcode.com/databases/mysqltutorial/views

×