View in SQL Server
The view is a virtual table based on the result-set of an SQL statement.
A view contains rows and columns like a real table.
Views are used for security purposes in databases.
A view can combine data from two or more tables, using joins, and also contain a subset of information.
A view does not store data.
There are two types of views in SQL.
Simple View:- Simple views can only contain a single base table.
INSERT, DELETE and UPDATE are directly possible on a simple view.
Complex View:- Complex views can be constructed on more than one base table.
complex views can contain join conditions, a group by clause, order by clause.
cannot apply INSERT, DELETE and UPDATE on complex view directly.
Creating View:
Syntax:
Get Pooja Patil’s stories in your inbox
Join Medium for free to get updates from this writer.
CREATE VIEW view_name As
SELECT col1,col2…
FROM table_name
WHERE condition;
Deleting View:- A view is deleted with the DROP VIEW command.
Syntax:
DROP VIEW view_name;
Updating a View:- A view can be updated with the CREATE OR REPLACE VIEW command.
Syntax:
CREATE OR REPLACE VIEW view_name As
SELECT col1,col2,…
FROM table_name
WHERE condition;
If you are new to SQL Server start with the following must-watch video: -








