Introduction
In this blog, we will discuss how to work with Views in SQL Server and learn the concepts with an example in a simple way. I hope this is very useful for beginners to help them understand the basic concept.
View
A View is a Select statement or SQL query that contains the data from one base table or multiple tables in a virtual table that has no physical storage space. When we perform some operation on the View, it is applied to the base tables on which the View is created.
Basically, whenever the DBA or any developer creates the database, the database is set up in a very normalized way, so the data is divided into multiple tables to display the required columns and to reduce the complexity of the database schema, Views are used.
We create the views for security purposes since it restricts the user to view some columns or fields of the tables and hide the sensitive information and display the data from one base table or multiple tables virtually. As a security mechanism by allowing users to access the data through the View, without granting the users permissions to directly access the underlying base tables.
Views show only those columns that are present at a time query preparation or create the View.
Types of View
- User Defined View
- Simple View
- Complex View
- System Defined View
- Information Schema View
- Catalog View
- View Create Information/Script
VehicleModels
- CREATE TABLE VehicleModels
- (
- Id int primary key identity,
- Model nvarchar(40),
- Description nvarchar(80),
- TotProdctionCost money,
- ProdctionSellingPrice money
- )
- Insert into VehicleModels values('L551','L551',51000, 71000)
- Insert into VehicleModels values('L550','L550',41000, 61000)
- Insert into VehicleModels values('L538','L538',31000, 51000)
- Select * from VehicleModels
Output

- CREATE TABLE Customers
- (
- Id int primary key identity,
- FirstName nvarchar(40),
- LastName nvarchar(40),
- Address nvarchar(80),
- City nvarchar(40),
- State nvarchar(40),
- Country nvarchar(40)
- )
- Insert into Customers values('Shrimant','T','ABC','Latur','Maharashtra','India')
- Insert into Customers values('Arun','J','ABC','Latur','Maharashtra','India')
- Insert into Customers values('Kishor','D','ABC','Latur','Karnataka','India')
- Insert into Customers values('Madhav','S','ABC','Latur','Karnataka','India')
- Insert into Customers values('Jitendra','W','ABC','Latur','Hydrabad','India')
- Insert into Customers values('Tukaram','M','ABC','Latur','Hydrabad','India')
- Insert into Customers values('Aditya','W','ABC','Latur','Gujrath','India')
- Insert into Customers values('Harsha','M','ABC','Latur','Gujrath','India')
- Select * from Customers
Output

- CREATE TABLE ProductionTransactions
- (
- Id int primary key identity,
- CustomerId int foreign key references Customers(Id),
- VehicleModelId int foreign key references VehicleModels(Id),
- DateofBooking datetime,
- Qty int
- )
- Insert into ProductionTransactions values(1,1, DATEADD(month, -2, GETDATE()),2)
- Insert into ProductionTransactions values(2,2, DATEADD(month, -2, GETDATE()),3)
- Insert into ProductionTransactions values(3,3, DATEADD(month, -1, GETDATE()),1)
- Insert into ProductionTransactions values(4,1, DATEADD(month, -1, GETDATE()),2)
- Insert into ProductionTransactions values(5,2, DATEADD(month, -1, GETDATE()),1)
- Insert into ProductionTransactions values(6,3, DATEADD(month, -1, GETDATE()),2)
- Insert into ProductionTransactions values(7,1, DATEADD(month, -2, GETDATE()),2)
- Insert into ProductionTransactions values(8,1, DATEADD(month, -2, GETDATE()),2)

User Defined View
Simple View
If view is created on a single table then the view is called simple view. We will execute CREATE, UPDATE, DELETE operation on view based on above tables.
Creating View













Rajesh KumarPosted Aug 31, 2018, 12:29 AM
Nice article...........