CREATE VIEW
The CREATE VIEW
statement creates a virtual table based on the result set of an SQL query. Views can be aliased and reused in other queries.
Syntax Summary
This code block is a quick reference with all the parameters that you can use with the CREATE VIEW
statement.
See some practical examples.
CREATE [ OR REPLACE ] VIEW [ IF NOT EXISTS ] name
AS query
Parameters
The CREATE VIEW
statement accepts the following parameters.
You must provide the following:
-
name
-
query
Parameter | Description |
---|---|
|
Create a new view only if a view of the same name does not already exist (recommended). |
|
Overwrite an existing view of the same name. |
|
Name of the view. This name must be unique. |
|
A |
Dependency Management
If you change a mapping that a view depends on, you will invalidate that view. Also, if you drop a column from a mapping that the view v
depends on, the command will succeed. However, subsequent
queries such as SELECT * FROM v
will fail because the column is missing.
The command to drop a column from the mapping succeeds because the query
parameter in the view isn’t validated until the next time it is used.
Dropping or modifying a view that’s used in an active query does not affect the query; it will have effect only on newly-submitted queries.
Information Schema Views
The information_schema.views
view provides a view into the engine metadata for the user. View
columns are in information_schema.columns
table.
Permissions
Enterprise
If security is enabled, you can grant or deny permission for certain clients to use this statement. See SQL Permissions.