In this blog, I’m trying to explain the views in sql server and how to create it.
A view can be thought of as either a virtual table or a stored query. It enables you to partition the information horizontally or vertically from one or more tables. With a view, the users can see only the selected fields or selected rows.
A view can only be created in the current database. When a view is created, the name of the view is stored in the sysobjects table and the text of the CREATE VIEW statement is stored in syscomments table.
Creating Views
A view can be created using CREATE VIEW statement.
Syntax:
CREATE VIEW View_Name
AS
SELECT_statements
Example
CREATE VIEW vwEMP
AS
SELECT EMPFIRSTNAME,EMPLASTNAME
FROM EMP
Output
SELECT * FROM vwEMP
Alter Views
Alter view statement is used to change the definition of the view.
Example
ALTER VIEW vwEMP
AS
SELECT EMPFIRSTNAME,EMPLASTNAME,SALARY
FROM EMP
Output
SELECT * FROM vwEMP
Dropping Views
A view can be dropped using the DROP VIEW statement.
Syntax:
DROP VIEW View_Name
Example
DROP VIEW vwEMP
Leave Comment