DROP TABLE (Transact‑SQL)
Syntax
DROP TABLE [ IF EXISTS ]
{
[ schema_name . ] table_name
| [ database_name . [ schema_name ] . ] table_name
} [ , …n ]
[ ; ]
The DROP TABLE
statement removes one or more tables from the database. Use IF EXISTS
to avoid an error if the table does not exist.
Parameters
- IF EXISTS – Optional. Prevents an error when the specified table does not exist.
- schema_name – Optional schema qualifier. Defaults to
dbo
. - table_name – Name of the table to drop.
- database_name – Optional database qualifier.
Remarks
- The table and its indexes, constraints, triggers, and permission specifications are removed.
- Dropping a table that is referenced by a FOREIGN KEY constraint in another table fails unless that constraint is removed first.
- Use
DROP TABLE
to delete temporary tables (e.g.,#temp
or##temp
).
Examples
Example 1 – Drop a Single Table
DROP TABLE dbo.Employees;
Example 2 – Drop Multiple Tables
DROP TABLE dbo.Customers, dbo.Orders;
Example 3 – Drop a Table If It Exists
DROP TABLE IF EXISTS dbo.TempData;