SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server - DROP VIEW Keyword



The SQL Server (Transact-SQL) DROP VIEW statement is used to delete a SQL Server VIEW. A SQL Server VIEW is a virtual table created based on the SQL Server statement. A view contains rows and columns just like a normal table. All SQL Server functions, WHERE, HAVING and JOINs statements can be used to create a SQL Server VIEW. Finally, to delete a SQL Server VIEW, DROP VIEW keyword is used.

Syntax

The syntax for using DELETE VIEW statement in SQL Server (Transact-SQL) is given below:

DROP VIEW view_name;

Example:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

The below mentioned SQL Server statement is used to create a view on Employee table which contains all records of employee whose salary is greater than 2800.

CREATE VIEW [Employee Salary GT 2800] AS
SELECT * FROM Employee WHERE Salary > 2800;

After creating the VIEW, it can be used as mentioned below:

SELECT * FROM [Employee Salary GT 2800];

This will produce the result as shown below:

EmpIDNameCityAgeSalary
1JohnLondon253000
4KimAmsterdam303100
5RameshNew Delhi283000

The DROP VIEW keyword is used to delete a view.

DROP VIEW [Employee Salary GT 2800];

❮ SQL Server Keywords

5