Home » Sql Server Create View

Sql Server Create View

by Online Tutorials Library

SQL Server Create View

A view is a virtual table created according to the result set of an SQL statement.

A view contains rows and columns, just like a real table. The columns in the view are the columns from one or more real tables in the database. SQL functions, WHERE, and JOIN statements can also be added to the view.

There are two ways to create a view in SQL Server:

  • By using SQL Server management studio UI.
  • By using SQL Server query statement.

By using SQL Server management studio UI

Open SQL Server Management Studio.

SQL Create view 1

Here you see view. Go to view and click right.

SQL Create view 2

Now you will see a page like this. Choose a table on which you want to create a view. Here we select “Student” table.

SQL Create view 3

Click on the add button.

A view is created.


By using SQL Server query statement.

Syntax:

SQL Create VIEW Example

Let’s create a view named “Student_name” which contains all data from table “Student” where id is >3.

Output:

SQL Create view 4

View is created successfully.

You can verify that created view:

SQL Create view 5

Now query the view:

Output:

SQL Create view 6


Update a View

You can update a view by using ALTER VIEW statement.

Syntax:

Now add a column “fee” to the created view “Student_view” from the table “Student”. Use the following statement:

Output:

SQL Create view 7

You can see that view is updated successfully. Verify it by using SELECT statement:

SQL Create view 8

Output:

SQL Create view 9


SQL Server DROP a View

DROP VIEW command is used to delete a view.

Syntax:

Example:

Let’s delete the view “Student_view”.

Output:

SQL Create view 10

Now you can see that view is deleted.

Next TopicBackup Database

You may also like