How to Create a View in SQL Server Management Studio

In this SQL Server tutorial, I will show you how to create a view in SQL Server Management Studio.

You may be familiar with a query or the command that allows you to create a view but want to extend your knowledge to create a view using the SSMS, so I have explained step by step how to do that here.

As a database administrator, sometimes I need to run complex queries on the database to retrieve information, and the view is very helpful; I mostly use the view to get information from the table, which is based on the complex script.

This SSMS provides an easy interface for creating a view. Once you are familiar with it, you can quickly create a view.

How to Create a View in SQL Server Management Studio

First, let me define the view. A view is a logical or virtual table that doesn’t store data. However, when you call the view, it returns the data from the table. Also, don’t be confused that the view is a real table.

But you may wonder, what exactly is a view? The view is the query executed whenever it is called, but why does it contain a query? You can also directly the query in the query editor to get the same result.

You are right, but the view has advantages. For example, suppose you have to execute a complex query or length query to retrieve information or perform an operation on the table. In that case, you will write that query in your query editor area.

If you need that kind of information again, you will write that complex query again. If you need it several times, would you like to write these queries repeatedly? I don’t think so.

Now, you can encapsulate those complex queries into the view, so whenever you need that complex query, call the view. You understand what view is and why it is required.

Let’s create a view using the SQL Server Management Studio.

First, open the SSMS and connect the SQL Server instance to create a view. Now go to the Object Explorer section and choose the database where you want to create a view.

Then, choose the Views folder and right-click on it; from the properties option, select New View, as shown in the picture below.

To Create a View in SQL Server Management Studio Choosing New View Option

When you select the New View option, the Add Table dialogue opens; in the dialogue, you see the four tables: Table, Views, Functions and Synonyms.

Switch to the Tables tab and select a table, such as the one in the picture below; I am choosing the Customers table.

To Create a View in SQL Server Management Studio Selecting Table Customers

After selecting the table, a small Diagram Pane opens where you need to choose the columns that you want to include in your view. See the picture below.

To Create a View in SQL Server Management Studio Selecting Table Columns to Include in View

The above picture shows that the two-column customer_name and email are included in the view.

To save the view, click on the File menu in the top-left of the interface of SSMS and then click on the ‘Save MSI.web-dbo.view_1’; in your case, it can be a different name, as shown below.

Saving View By Clicking on the File Menu

An alternate way to save the view is to press Ctrl+S from your keyboard. A Choose Name dialog box will appear. Enter the view name in the box and click the OK button, as shown in the picture below.

To Create a View in SQL Server Management Studio

Look, I have specified the view name as ‘Customer_view’. When you click the OK button, your Views database folder creates a new view of that name. Expand the Views folder, as shown in the picture below, to check the view.

Showing the View in SQL Server Management Studio

Look at the picture; the Views folder contains the view ‘dbo.Customer_view’ you created.

Now, you can create a view in SQL Server Management Studio by following the above procedures.

If you want to create any view, follow the above steps, and you can create a view.

Conclusion

In this SQL Server tutorial, you learned how to create a view in SQL Server Management, how to select a table for views, and how to include the table’s columns in the view.

You may like to read: