O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required