Skip to content

Latest commit

 

History

History
116 lines (86 loc) · 4.74 KB

File metadata and controls

116 lines (86 loc) · 4.74 KB
title DROP VIEW (Transact-SQL) | Microsoft Docs
ms.custom
SQL2016_New_Updated
ms.date 06/02/2016
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
DROP_VIEW_TSQL
DROP VIEW
dev_langs
TSQL
helpviewer_keywords
dropping views
DROP VIEW statement
deleting views
indexed views [SQL Server], removing
views [SQL Server], removing
removing views
ms.assetid 03cea355-e39c-46e1-b7db-8832038669dd
caps.latest.revision 42
author BYHAM
ms.author rickbyh
manager jhubbard

DROP VIEW (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all_md]

Removes one or more views from the current database. DROP VIEW can be executed against indexed views.

Topic link icon Transact-SQL Syntax Conventions

Syntax

-- Syntax for SQL Server and Azure SQL Database  
  
DROP VIEW [ IF EXISTS ] [ schema_name . ] view_name [ ...,n ] [ ; ]  
-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse  
  
DROP VIEW [ schema_name . ] view_name   
[;]  

Arguments

IF EXISTS

Applies to: [!INCLUDEssNoVersion] ([!INCLUDEssSQL15] through current version).

Conditionally drops the view only if it already exists.

schema_name
Is the name of the schema to which the view belongs.

view_name
Is the name of the view to remove.

Remarks

When you drop a view, the definition of the view and other information about the view is deleted from the system catalog. All permissions for the view are also deleted.

Any view on a table that is dropped by using DROP TABLE must be dropped explicitly by using DROP VIEW.

When executed against an indexed view, DROP VIEW automatically drops all indexes on a view. To display all indexes on a view, use sp_helpindex.

When querying through a view, the [!INCLUDEssDE] checks to make sure that all the database objects referenced in the statement exist and that they are valid in the context of the statement, and that data modification statements do not violate any data integrity rules. A check that fails returns an error message. A successful check translates the action into an action against the underlying table or tables. If the underlying tables or views have changed since the view was originally created, it may be useful to drop and re-create the view.

For more information about determining dependencies for a specific view, see sys.sql_dependencies (Transact-SQL).

For more information about viewing the text of the view, see sp_helptext (Transact-SQL).

Permissions

Requires CONTROL permission on the view, ALTER permission on the schema containing the view, or membership in the db_ddladmin fixed server role.

Examples

A. Drop a view

The following example removes the view Reorder.

USE AdventureWorks2012 ;  
GO  
  
DROP VIEW dbo.Reorder ;  
GO  

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

B. Drop a view

The following example removes the Reorder view from the local database.

DROP VIEW Reorder;  

See Also

ALTER VIEW (Transact-SQL)
CREATE VIEW (Transact-SQL)
EVENTDATA (Transact-SQL)
sys.columns (Transact-SQL)
sys.objects (Transact-SQL)
USE (Transact-SQL)
sys.sql_expression_dependencies (Transact-SQL)