SQL CREATE VIEW

From Recital Documentation Wiki
Jump to: navigation, search

Purpose

Creates a logical view based on one or more tables


Syntax

CREATE [SQL] VIEW <view> [(<alias> [,...])] AS <sub-query>


See Also

DROP VIEW, SELECT


Description

The CREATE VIEW or CREATE SQL VIEW commands create a logical view based on one or more tables. A view is a logical table that allows you to access data from other tables. A view itself contains no data.


Keywords Description
view The name of the view to be created.
alias This is an optional identifier that names a column in the view. The number of columns that you name must match the number of columns in the sub-query
AS sub-query This identifies columns and rows of the tables from which the view is created. The sub-query is a SELECT statement.


When the view is created, the view definition is written into the sysodbc.ini file in the current directory. If no sysodbc.ini file currently exists, it will be created. The DROP VIEW command removes the view definition from this file. The view will be available until the DROP VIEW command is issued or the sysodbc.ini file is manually modified. The data extracted from the view is the data current at the time of the SELECT statement, not at the time of the view creation.


Example

// Create a view based on price being over $10
CREATE VIEW OverTen AS;
SELECT * FROM orders WHERE price > 10
 
// Create a view based on price being over $20
CREATE SQL VIEW OverTwenty AS;
SELECT * FROM orders WHERE price > 20


Products

Recital Server, Recital