4D v14CREATE VIEW |
||||||||||||||||||||||||
|
4D v14
CREATE VIEW
CREATE VIEW
The CREATE VIEW command creates an SQL view named view_name (which is a standard sql_name) containing the columns defined in the column_list parameter. You will need to specify a column name if this column is a function or is derived from an arithmetic operation (scalar). It is also necessary to specify a column name if you want to avoid having different columns with the same name (for example, during a JOIN operation) or when you want to use a different column name than the one from which it is derived. If the column_list parameter is passed, it must contain the same number of columns as there are in the select_statement definition query of the view. If column_list is omitted, the columns of the view will have the same names as those of the columns in the select_statement of the view. Views and tables must have unique names. If you pass the OR REPLACE option, the view is automatically created again if it already exists. This option can be useful in order to change the definition of an existing view without having to delete/re-create/affect the privileges of objects already defined for the current view. schema_name is also a standard sql_name and you can use it to designate the name of the schema that will contain the view. If you do not pass schema_name or if you pass the name of a schema that does not exist, the view is automatically assigned to the default schema, which is entitled "DEFAULT_SCHEMA". select_statement designates the SELECT that is the definition query of the view. The select_statement is the same as a standard SELECT in 4D, but with the following restrictions:
View definition is "static" and is not updated when a source table is modified or deleted. More particularly, any columns added to a table do not appear in the view based on this table. Similarly, if you try to access deleted columns by means of a view, this causes an error. Views have a global scope. Once a view is created using CREATE VIEW, it can be accessed by all parts of the application (4D remote using SQL, external databases created using the CREATE DATABASE command, other databases using the SQL LOGIN command, etc.) and at any time until it is deleted using the DROP VIEW command. Here are a few examples of view definitions, given a PEOPLE table containing the following columns:
A view with no restrictions: CREATE VIEW FULLVIEW AS A view with "horizontal" restrictions. For example, you want to only display people in the Marketing department: CREATE VIEW HORIZONTALVIEW (ID, FirstName, LastName, Salary) AS An aggregated view: CREATE VIEW AGGREGATEVIEW (FirstName, LastName AnnualSalary) AS A view with "vertical" restrictions. For example, you do not want to display the SALARY column: CREATE VIEW VERTICALVIEW (ID, FirstName, LastName, Department) AS Once the views are defined, you can use them just like standard tables. For example, if you want to get every person whose salary is greater than 5,000 Euros: SELECT * FROM FULLVIEW Another example: you want to get every person in the Marketing department whose first name is "Michael": SELECT ID, LastName, Salary FROM HORIZONTALVIEW |
PROPERTIES
Product: 4D SEE ALSO ARTICLE USAGE
4D SQL Reference ( 4D v14) |
||||||||||||||||||||||