create view (core)

Description

Creates a new view.

Syntax

Transact-SQL Syntax

create view [owner.]view_name
[(column_name [, column_name]...)]
 as select [distinct] select_statement
[with check option]

ODBC Syntax

CREATE VIEW viewed_table_name
[(column_identifier[,column_identifier]...)]
AS query_specification

Parameters

select

begins the select statement that defines the view.

distinct

specifies that the view cannot contain duplicate rows (optional).

with check option

indicates that all data modification statements are validated against the view selection criteria. All rows inserted or updated through the view must remain visible through the view.

view_name

is the name of the view. The view name cannot include the database name. It must conform to the rules for identifiers.

column_name

is the name of the column in the view. It must conform to the rules for identifiers.

select_statement

completes the select statement that defines the view. It can include more than one table and other views.

Examples

Example 1

create view “new view” (“column 1”, “column 2”)
 as select col1, col2 from “old view”

In this example, the new view is created from the old view.Both columns are renamed in the new view. All view and column names that include embedded blanks are enclosed in double quotation marks. Before creating the view, you must set the quoted_identifier property to on.

Usage