Create Views
You can create views in SQL Server 2012 by using SQL Server Management Studio or Transact-SQL. A view can be used for the following purposes:
To focus, simplify, and customize the perception each user has of the database.
As a security mechanism by allowing users to access data through the view, without granting the users permissions to directly access the underlying base tables.
To provide a backward compatible interface to emulate a table whose schema has changed.
In This Topic
Before you begin:
Limitations and Restrictions
Security
To create a view, using:
SQL Server Management Studio
Transact-SQL
Before You Begin
Limitations and Restrictions
A view can be created only in the current database.
A view can have a maximum of 1,024 columns.
Security
Permissions
Requires CREATE VIEW permission in the database and ALTER permission on the schema in which the view is being created.
[Top]
Using SQL Server Management Studio
To create a view by using the Query and View Designer
In Object Explorer, expand the database where you want to create your new view.
Right-click the Views folder, then click New View….
In the Add Table dialog box, select the element or elements that you want to include in your new view from one of the following tabs: Tables, Views, Functions, and Synonyms.
Click Add, then click Close.
In the Diagram Pane, select the columns or other elements to include in the new view.
In the Criteria Pane, select additional sort or filter criteria for the columns.
On the File menu, click Save view name.
In the Choose Name dialog box, enter a name for the new view and click OK.
For more information about the query and view designer, see Query and View Designer Tools (Visual Database Tools).
[Top]
Using Transact-SQL
To create a view
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, click New Query.
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2012 ; GO CREATE VIEW HumanResources.EmployeeHireDate AS SELECT p.FirstName, p.LastName, e.HireDate FROM HumanResources.Employee AS e JOIN Person.Person AS p ON e.BusinessEntityID = p.BusinessEntityID ; GO -- Query the view SELECT FirstName, LastName, HireDate FROM HumanResources.EmployeeHireDate ORDER BY LastName;
For more information, see CREATE VIEW (Transact-SQL).
[Top]