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 the same in SQL Server 2014 as they were in SQL Server 2012 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 24.2 shows a sample T-SQL statement for creating a simple view.

LISTING 24.2

Get Microsoft SQL Server 2014 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.