Entering content frame

CREATE VIEW Statement (create_view_statement) 

The CREATE VIEW statement defines a view table (see Table). A view table never actually exists physically. Instead, it is formed from the rows of the underlying base table(s) when this view table is specified in an SQL statement.

Syntax

<create_view_statement> ::= CREATE [OR REPLACE] VIEW <table_name> [(<alias_name>,...)] AS <query_expression> [WITH CHECK OPTION]

table_name, alias_name, query_expression

Explanation

When the CREATE VIEW statement is executed, metadata that describes the view table is stored in the catalog.

The view table is always identical to the table that would be obtained as the result of the QUERY expression. The QUERY expression must not contain a parameter specification. The QUERY expression must not reference a temporary table or a result table name.

The table expressions of the QUERY specification in the QUERY statement of the CREATE VIEW statement must not contain a QUERY expression.

If a column selected by the QUERY statement is of the data type LONG, the FROM clause must contain exactly one table name that is based on exactly one base table.

The user must have the SELECT privilege for all columns occurring in the view definition. The user is the owner of the view table and has at least the SELECT privilege for it. The user may grant the SELECT privilege for any columns in the view table derived from columns for which the user is authorized to grant the SELECT privilege to others. The user has the INSERT, UPDATE, or DELETE privilege when he has the corresponding privileges for the tables on which the view table is based, and when the view table is updateable. The user may only grant these privileges to others if he or she is authorized to grant the corresponding privilege for all tables on which the view table is based.

OR REPLACE

If OR REPLACE is not specified, the table name must not be identical to the name of an existing view table.

If OR REPLACE is specified, the table name may be identical to the name of an existing view table. In this case, the definition of the existing view table is replaced by the new definition. The database system then attempts to adapt privileges granted for the existing view table to the new view definition, with the result that the privileges for the view table usually remain unchanged. Privileges are only removed implicitly if conflicts occur that cannot be resolved by the database system. If there are major discrepancies between the two view definitions, the CREATE VIEW statement may fail in the following case: the CREATE VIEW statement of a view table based on the existing view table cannot be executed correctly for the new view definition.

Alias names (alias_name)

The column names of the view table must be unique. Otherwise, alias names must be specified for the result table generated by the QUERY expression. The number of alias names must be equal to the number of columns in the result table generated by the QUERY expression. If no alias names are specified, the column names of the result table generated by the QUERY expression are applied to the view table. The column descriptions for the view table are taken from the corresponding columns in the query expression. The FROM clause of the QUERY expression can contain one or more tables.

WITH CHECK OPTION

If the create view statement contains a WITH CHECK OPTION, the owner of the view table must have the INSERT, UPDATE, or DELETE privilege for the view table.

Specifying WITH CHECK OPTION has the effect that the insert statement or update statement issued on the view table does not create any rows that could not be selected subsequently via the view table; i.e. the search condition of the view table must be true for any resulting rows.

The CHECK OPTION is inherited; i.e. if a view table V was defined WITH CHECK OPTION and V occurs in the from clause of an updateable view table V1, only those rows that can be selected using V can be inserted or altered using V1.

Further terms and information

·        Complex View Table

·        Updateable View Table

·        INSERT Privilege for Owners of the View Table

·        UPDATE Privilege for Owner of the View Table

·        DELETE Privilege for Owner of the View Table

·        Updateable Join View Table

 

Leaving content frame