DROP (Transact‑SQL)
The DROP
statement removes an existing database object, such as a table, view, stored procedure, or index. Once dropped, the object and its data are no longer available.
Syntax
DROP <object_type> [ IF EXISTS ] <object_name> [ , <object_name>... ] [;]
Common <object_type>
values include:
Object Type | Example |
---|---|
TABLE | DROP TABLE dbo.Customers; |
VIEW | DROP VIEW dbo.vCustomerSummary; |
PROCEDURE | DROP PROCEDURE dbo.usp_GetOrders; |
FUNCTION | DROP FUNCTION dbo.fn_CalculateTax; |
INDEX | DROP INDEX IX_CustomerName ON dbo.Customers; |
Parameters
- IF EXISTS – Prevents an error if the object does not exist.
- object_name – The schema‑qualified name of the object to drop.
- ; – Optional statement terminator.
Examples
-- Drop a table if it exists
DROP TABLE IF EXISTS dbo.OldOrders;
-- Drop multiple objects in a single statement
DROP VIEW dbo.vSalesSummary, dbo.vCustomerActivity;
/* Remove an index */
DROP INDEX IX_EmployeeLastName ON dbo.Employees;
Remarks
Dropping an object is a non‑reversible operation. Ensure you have backups or have verified that the object is no longer needed before executing a DROP
statement.
When dropping tables that have dependent objects (such as foreign key constraints), you must first drop or alter those dependencies.