DROP Table
The DROP TABLE statement permanently removes a table from a database - deleting its structure and all the data it contains. This action generally cannot be undone.
Basic Syntax
DROP TABLE customers;
Safer Usage
Using IF EXISTS prevents an error if the table doesn't exist, which is useful in scripts that may run more than once:
DROP TABLE IF EXISTS customers;
DROP vs DELETE vs TRUNCATE
- DROP TABLE - removes the entire table structure and its data permanently
- DELETE - removes rows from a table but keeps the table structure intact
- TRUNCATE - quickly removes all rows but keeps the table structure, faster than DELETE for clearing an entire table
Because DROP TABLE is irreversible, always double-check the table name (and take a backup if it's a production database) before running it.