Creating Views Using T-SQL

The CREATE VIEW statement is used to create views with T-SQL. The syntax for the CREATE VIEW statement follows:

CREATE VIEW [ schema_name . ] view_name [ (column [ ,...n ] ) ][ WITH <view_attribute> [ ,...n ] ]AS select_statement [ ; ][ WITH CHECK OPTION ]<view_attribute> ::={    [ ENCRYPTION ]    [ SCHEMABINDING ]    [ VIEW_METADATA ]     }

This statement and the related options are essentially the same in SQL Server 2012 as they were in SQL Server 2008 and prior versions. We first look at a simple example for creating a view with T-SQL and then delve into several other examples that utilize the view attributes. Listing 23.2 shows a sample T-SQL statement for creating a simple view.

Get Microsoft® SQL Server 2012 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.