Learning objective: In this tutorial, you will learn how to user SQL Server
DROP VIEW statement to remove an existing view from the SQL Server Database.
SQL Server DROP VIEW Syntax
To drop a view from SQL Server database, you need to use the following syntax:
DROP VIEW [IF EXISTS] schema_name.view_name;
In this syntax,
- DROP VIEW – Mandatory. The keyword to drop an existing view from the SQL Server Database.
- [IF EXIST] – Optional. If specified, SQL Server will check if the specified view is present or not in the database. If not specified, SQL Server prompt an error.
IF EXISTclause prevents SQL Server for prompting error if the specified view does not exist in the database.
- schema_name – The name of the schema where the view belongs.
- view_name – The name of the view which you want to remove from the SQL Server database.
In order to remove multiple views in a single statement, you can use the following syntax.
DROP VIEW [IF EXISTS] schema_name.view_name1, schema_name.view_name2, … ;
Here, views are specified with the commas.
SQL Server DROP VIEW examples
Suppose, we have below three views created in
We will use the above three views to demonstrate DROP VIEW in SQL Server.
Removing one view example
The below example shows how to drop vWProductSales view from the
DROP VIEW IF EXISTS dbo.VwProductSales;
Removing Multiple views examples
The following statement remove both dbo.vWTopThreeProductBySales and dbo.vWTotalSalesByProduct views at the same time.
DROP VIEW IF EXISTS dbo.vWTopThreeProductBySales, dbo.vWTotalSalesByProduct;
Summary: In this tutorial, you have learned how remove single and multiple views from the SQL Server Database.