Rediger

Del via


Delete views

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)

You can delete (drop) views in the SQL Server Database Engine by using SQL Server Management Studio or Transact-SQL

Limitations and restrictions

  • 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.

Permissions

Requires ALTER permission on SCHEMA or CONTROL permission on OBJECT.

Use SQL Server Management Studio

  1. In Object Explorer, expand the database that contains the view you want to delete, and then expand the Views folder.

  2. Right-click the view you want to delete and select Delete.

  3. 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.

Use Transact-SQL

  1. In Object Explorer, connect to an instance of Database Engine.

  2. On the Standard bar, select New Query.

  3. 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 SQL Server 2016 (13.x):

    USE AdventureWorks2022;
    GO
    
    DROP VIEW IF EXISTS HumanResources.EmployeeHireDate;
    GO
    

Next steps