Sunday, August 26, 2012

Mysql Table Views

     A view is a specific look or a peek on data from one or more tables. It is created to act as a dynamic, virtual table computed or collated from the data in the database. It acts like a table or is simply a psuedo-table. It is a query that is stored and is named like a table and it can be referenced like a table. Its field can be from one or more real tables in the database. If you insert, edit or delete a data in the view from which the view comes from one table only that data will also be altered in the real table. But if you try to alter a data in a view from different tables mysql does not allow such alteration thus you will end in an error.
     To create a view you will need to use this syntax:
     CREATE VIEW name_of_view AS
     SELECT column_names 

     FROM table_name
     WHERE condition


     In creating views you can use all of the different types queries available in mysql like the ones with the JOIN clause and GROUP clause and with different conditions you like.
     To query a view, you can query like an ordinary table. Alteration of the view will only be acceptable if the view is from only one table. To show the list of views you can use the SHOW FULL TABLES statement.
     Here is an example:

No comments:

Post a Comment