CREATE VIEW
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Creates a view with the specified name on existing tables or views.
Syntax
|
Parameters
- owner_name
-
Owner of the created view.
- ( column_name, column_name,... )
-
Specifies column names for the view. These names provide an alias for the columns selected by the query specification. If the column names are not specified, then the view is created with the same column names as the tables or views on which it is based.
- WITH CHECK OPTION
-
Checks that the updated or inserted row satisfies the view definition. The row must be selectable using the view. The
WITH CHECK OPTIONclause is only allowed on an updatable view.To determine the authorization (privileges) of a view and to enable effective employment of the view, you must execute two
GRANTstatements along with theCREATE VIEWstatement. TheGRANTstatements give access to the view and enables the view to access the underlying database tables.The syntax for these statements is given below:
CREATE VIEW ... GRANT {privilege[, privilege] , ... | ALL [ PRIVILEGES]} ON schema_name view_name TO { username [, username ] , ... | PUBLIC } GRANT {privilege[, privilege] , ... | ALL [ PRIVILEGES]} ON table_name TO schema_name; - privilege
-
Uses the following syntax:
{ SELECT | INSERT | DELETE | INDEX | UPDATE [( column , column , ... ) [| REFERENCES [( column , column , ... )]}
Notes
- A
view is deletable if deleting rows from that view is allowed. For a
view to be deletable, the view definition must satisfy the following
conditions:
- The first
FROMclause contains only one table reference or one view reference. - There are no aggregate functions,
DISTINCTclause,GROUP BYclause, orHAVINGclause in the view definition. - If the first
FROMclause contains a view reference, then the view referred to is deletable.
- The first
- A view is updatable if updating rows from that view is allowed.
For a view to be updatable, the view has to satisfy the following
conditions:
- The view is deletable (it satisfies all the previously specified conditions for deletability).
- All the select expressions in the first
SELECTclause of the view definition are simple column references. - If the first
FROMclause contains a view reference, then the view referred to is updatable.
- A view is insertable if inserting rows into that view is allowed.
For a view to be insertable, the view has to satisfy the following
conditions:
- The view is updatable (it satisfies all the previously specified conditions for update ability).
- If the first
FROMclause contains a table reference, then allNOT NULLcolumns of the table are selected in the firstSELECTclause of the view definition. - If the first
FROMclause contains a view reference, then the view referred to is insertable.
Examples
CREATE VIEW statement
The following examples illustrate CREATE VIEW statements defined by query expressions:
|
Granting privileges on a view
The
below statement creates a view mtInvoiceView1 for
the table pub.mtinvoice:
|
The below statement grants only SELECT privileges on
the view:
|
The below statement grants only UPDATE privileges on
the view:
|
The below statement grants the schema that owns the view the authorization to select data from the table that the view accesses. Other privileges can also be granted. All table accessed by the view must be granted to the schema that owns the view.
|