title | description | author | ms.author | ms.reviewer | ms.date | ms.service | ms.subservice | ms.topic | helpviewer_keywords | monikerRange | ||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Delete views |
Delete (drop) views in the Database Engine using SQL Server Management Studio or Transact-SQL. |
WilliamDAssafMSFT |
wiassaf |
randolphwest |
05/10/2023 |
sql |
table-view-index |
how-to |
|
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDE sql-asdb-asdbmi-asa-pdw]
You can delete (drop) views in the [!INCLUDE ssdenoversion-md] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql]
-
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 usingDROP VIEW
.
Requires ALTER permission on SCHEMA or CONTROL permission on OBJECT.
-
In Object Explorer, expand the database that contains the view you want to delete, and then expand the Views folder.
-
Right-click the view you want to delete and select Delete.
-
In the Delete Object dialog box, select OK.
[!IMPORTANT]
Select Show Dependencies in the Delete Object dialog box to open the view_name Dependencies dialog box. This will show all of the objects that depend on the view and all of the objects on which the view depends.
-
In Object Explorer, connect to an instance of [!INCLUDEssDE].
-
On the Standard bar, select New Query.
-
Copy and paste the following example into the query window and select Execute. The example deletes the specified view only if the view already exists.
USE AdventureWorks2022; GO IF OBJECT_ID('HumanResources.EmployeeHireDate', 'V') IS NOT NULL DROP VIEW HumanResources.EmployeeHireDate; GO
You can also use the
IF EXISTS
syntax, introduced in [!INCLUDE sssql16-md]:USE AdventureWorks2022; GO DROP VIEW IF EXISTS HumanResources.EmployeeHireDate; GO