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
Open SQL Server Management Studio.
Here you see view. Go to view and click right.
Now you will see a page like this. Choose a table on which you want to create a view. Here we select "Student" table.
Click on the add button.
A view is created.
By using SQL Server query statement.
SQL Create VIEW Example
Let's create a view named "Student_name" which contains all data from table "Student" where id is >3.
View is created successfully.
You can verify that created view:
Now query the view:
Update a View
You can update a view by using ALTER VIEW statement.
Now add a column "fee" to the created view "Student_view" from the table "Student". Use the following statement:
You can see that view is updated successfully. Verify it by using SELECT statement:
SQL Server DROP a View
DROP VIEW command is used to delete a view.
Let's delete the view "Student_view".
Now you can see that view is deleted.