CREATE VIEW statement
Use the CREATE VIEW statement to create a new view that is based on one or more existing tables and views that reside in the database, or in another database of the local database server or of a different database server.
Syntax
Element | Description | Restrictions | Syntax |
---|---|---|---|
column | Name that you declare here for a column in view. Default is a column name from Projection list of SELECT. | See Naming View Columns. | Identifier |
owner | Owner of the view. If omitted, default is the user ID that issues the statement. | To specify another user ID requires DBA access privilege. | Owner name |
row_type | Named-row type for typed view | Must already exist in the database | Data Type |
view | Name that you declare here for the view | Must be unique among view, table, sequence, and synonym names in the database. | Identifier |
Usage
- ALTER FRAGMENT
- CREATE INDEX
- CREATE TABLE
- CREATE TRIGGER
- RENAME TABLE
- START VIOLATIONS TABLE
- STOP VIOLATIONS TABLE
- TRUNCATE
- UPDATE STATISTICS
Updating Through Views prohibits non-updatable views in INSERT, DELETE, or UPDATE statements (where other views are valid).
To create a view, you must have the Select privilege on all columns from which the view is derived. You can query a view as if it were a table, and in some cases, you can update it as if it were a table; but a view is not a table.
If you include the optional IF NOT EXISTS keywords, the database server takes no action (rather than sending an exception to the application) if a view of the specified name is already registered in the current database, or if the specified name is the identifier of a table, synonym, or sequence object in the current database.
The view consists of the set of rows and columns that the SELECT statement in the view definition returns each time you refer to the view in a query.
In some cases, the database server merges the SELECT statement of the user with the SELECT statement defining the view and executes the combined statements. In other cases, a query against a view might execute more slowly than expected, if the complexity of the view definition causes the database server to create a temporary table (referred to as a materialized view). For more information on materialized views, see the HCL OneDB™ Performance Guide.
- If a SELECT * specification defines the view, the view has only the columns that existed in the underlying tables when the view was defined by CREATE VIEW. Any new columns that are subsequently added to the underlying tables with the ALTER TABLE statement do not appear in the view.
- If a GRANT or REVOKE statement changes the discretionary access privileges on any table referenced in the view definition, the database server does not automatically apply those access privilege changes to the view.
The view inherits the data types of the columns in the tables from which the view is derived. The database server determines data types of virtual columns from the nature of the expression.
The SELECT statement is stored in the sysviews system catalog table. When you subsequently refer to a view in another statement, the database server performs the defining SELECT statement while it executes the new statement.
In DB-Access, if you create a view outside the CREATE SCHEMA statement, you receive warnings if you use the -ansi flag or if you set the DBANSIWARN environment variable.
CREATE VIEW v1 AS SELECT * FROM person;