The Basic View

Using SQL Server Management Studio, views may be created, modified, executed, and included within other queries, using either the Query Designer or the DDL code within the Query Editor.

Creating Views Using the Query Designer

Because a view is nothing more than a saved T-SQL SELECT statement, the creation of a view begins with a working SELECT statement. Any SELECT statement, as long as it's a valid SELECT statement (with a few minor exceptions), can be cut and pasted from nearly any other tool into the view designer.

Within SQL Server Management Studio, views are listed in their own node under each database.

The New View command in the context menu launches the Query Designer in a mode that creates views, as shown in Figure 11.1.

Figure 11.1 Creating a view in Management Studio's Query Designer.

11.1

The View Designer mode functions within Management Studio's Query Designer, which is also used to query tables. You can display or edit the actual T-SQL code for the view in the SQL pane. You can add columns to the view by using the Diagram pane, the Grid pane, or the SQL pane. The Add Table feature, available in the context menu or toolbar, can add tables, other views, synonyms, and table-valued functions.

You can add tables or other views to the new view by dragging them to the Diagram pane from the Object Explorer or using the Add Table context menu option.

You can use ...

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