SQL Server Views

Learning Objective

In this tutorial, you will learn what is a view in database, how views are created and used in SQL Server, how to list all the views in SQL Server, renaming a view, removing views from database.

SQL Server Views Introduction

SQL Server view is a virtual table and the content of the view is defined by a query. The query can refer one or more tables or views. Like a table, structure of a view is consist of set of named columns and rows of data. However, view does not store any data physically unless it is indexed. The columns and rows of a view come from the underlying table which are mentioned in the view definition.

Below are the few important point regarding views.

  1. View act as a filter between the data tables and users or applications.
  2. View does not occupy any storage as it does not store any data physically.
  3. Views are made from one or more tables or other views in the same or other databases.
  4. One of the main purpose of the view is to have some security mechanism. Using this, you no need to provide access directly to the underlying table to the user.
  5. Also column and row level security can be achieve using views.
  6. Views can also be used when you copy data to and from SQL Server to improve performance and to partition data.

SQL Server Views Example

Whenever we have to retrieve records which require more than one table, we used to write queries using subquery or joins.

For example, consider we have the following two tables in university schema.

Roll_NoNameAddress
1SagarSiliguri
2SajalKolkata
3ShuvadipDurgapur
4RajatDelhi
5PratikRajkot
6AdityaBangalore
StudentDetails
Roll_NoNameTotal_MarksAge
1Sagar9518
2Sajal6520
3Shuvadip7819
4Rajat7021
5Pratik8922
6Aditya5920
StudentMarks

Managing Views in SQL Server

Advertisement