DROP VIEW (Transact‑SQL)
The DROP VIEW statement removes an existing view from the database.
Syntax
DROP VIEW [ IF EXISTS ] { schema_name . } view_name [ ,...n ]
Parameters
| Parameter | Description |
|---|---|
IF EXISTS | Prevents an error if the view does not exist. |
schema_name | The schema that contains the view. |
view_name | The name of the view to be dropped. |
,...n | Allows multiple views to be dropped with a single statement. |
Remarks
- Dropping a view does not affect the underlying tables or other dependent objects.
- If other objects reference the view, they become invalid until recreated or altered.
- Permissions required:
DROPpermission on the view or membership in thedb_ownerrole. - When
IF EXISTSis used, no error is raised if the view does not exist.
Example
-- Drop a single view
DROP VIEW dbo.EmployeeView;
-- Drop multiple views with IF EXISTS
DROP VIEW IF EXISTS dbo.SalesView, dbo.InventoryView;
-- Verify removal
SELECT name FROM sys.views WHERE name = N'EmployeeView';