VIEW
suggest changeSyntax
- CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition; ///Simple create view syntax
- 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]; /// Full Create view syntax
- DROP VIEW [IF EXISTS] [db_name.]view_name; ///Drop view syntax
Parameters
Parameters | Details |
—— | —— |
view_name | Name of View |
SELECT statement | SQL statements to be packed in the views. It can be a SELECT statement to fetch data from one or more tables. |
Remarks
Views are virtual tables and do not contain the data that is returned. They can save you from writing complex queries again and again.
- Before a view is made its specification consists entirely of a
SELECTstatement. Before 5.7.7 thatSELECTcould not contain a subquery in theFROMclause. MySQL 5.7.7 and later allow it. - Once a view is made it is used largely just like a table and can be
SELECTed from just like a table.
A view can expose only some columns of a table.
- For example, managers and engineers can each have a view of
Salesthat includes only the columns they should see.
Performance. Views are syntactic sugar. Their performance may or may not be worse than the equivalent query with the view's SELECT folded in. The optimizer tries to do that, and is not always successful. MySQL 5.7.6 improved the optimizer further. A view does not make the query faster.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents