DROP TABLE permanently deletes a table — structure and all its data. There's no built-in undo.
Syntax
DROP TABLE table_name;
-- Safer: won't error if it doesn't exist
DROP TABLE IF EXISTS table_name;
Example
DROP TABLE IF EXISTS temp_import_batch;
Practical Use Case
Removing temporary or staging tables after a data-load process finishes, or cleaning up a table created for testing that's no longer needed.
DROP vs TRUNCATE vs DELETE — Quick Preview
| DROP TABLE | TRUNCATE TABLE | DELETE | |
|---|---|---|---|
| Removes | Table + data + structure | All rows, keeps structure | Rows matching a condition (or all) |
| Can use WHERE? | No | No | Yes |
| Undo with ROLLBACK? | Usually not (DDL) | Database-dependent | Yes (DML) |
Full comparison in TRUNCATE TABLE.
Common Mistakes
- Running DROP TABLE in production without a backup — this is one of the most common real-world disasters in SQL. Always confirm you're connected to the right database first.
- Using
DROP TABLEwhen you actually just wanted to empty it (that'sTRUNCATE) or remove specific rows (that'sDELETE) - Forgetting that dropping a table referenced by a foreign key in another table will fail (or cascade, depending on constraints) — check dependencies first
Interview Relevance
Q: "What happens to foreign key relationships when you drop a parent table?" Depends on the database and constraint setup — by default most databases block the drop if dependent rows/constraints exist, unless you explicitly cascade.
Practice Question
Write a statement that safely drops a table called old_logs_2023 without erroring if it's already gone.