SQL Drop Table
The DROP TABLE statement permanently removes a table and all of the data stored in it.
What DROP TABLE does
DROP TABLE deletes an entire table: its definition, its indexes, and every row it holds. After it runs, the table no longer exists in the database. Use it when a table is genuinely no longer needed, not simply when you want to clear its contents.
Basic syntax
DROP TABLE table_name;
-- Example: remove the employees table
DROP TABLE employees;Note: DROP TABLE cannot be undone. It removes the table structure and all rows at once. If you only want to erase the data but keep the empty table, use DELETE or TRUNCATE instead.
DROP versus TRUNCATE versus DELETE
These three commands are easy to confuse because all of them remove data, but they differ in what survives. DROP TABLE removes the table itself. TRUNCATE TABLE empties every row quickly while leaving the empty structure in place. DELETE removes rows one match at a time and can be limited with a WHERE clause.
Dropping safely and clearing rows
-- Drop only if the table exists, avoiding an error
DROP TABLE IF EXISTS employees;
-- Keep the table but remove every row
TRUNCATE TABLE employees;- Use DROP TABLE when the table is obsolete and should disappear entirely.
- Add IF EXISTS so teardown scripts do not fail on an already-removed table.
- Prefer TRUNCATE when you want a fast, clean reset that keeps the structure.
- Watch for foreign keys: another table referencing this one may block the drop until the dependency is removed.