DROP TABLE
In this page:
Deleting a Table
DROP TABLE permanently removes the table's structure and every row of data it held — unlike TRUNCATE, there's no table left behind afterward at all, structure included. Because this operation is irreversible without a backup, it's one of the most dangerous statements in everyday SQL work.
Example: Deleting a Table
DROP TABLE users;
Safe Table Deletion
Adding IF EXISTS avoids a fatal error when the table might already be gone, which is essential in idempotent migration or cleanup scripts run against unpredictable environments. Without IF EXISTS, running the same cleanup script twice in a row would throw an error on the second attempt.
Example: Safe Table Deletion
DROP TABLE IF EXISTS users;
Deleting Multiple Tables
You can list several table names separated by commas in a single DROP TABLE statement to remove them all at once, which is both faster and less error-prone than separate statements.
Example: Deleting Multiple Tables
DROP TABLE IF EXISTS users, orders, logs;
Deleting with Schema Contexts
Prefixing a table with its database name lets you drop a table in another database without first switching your session's active context via USE. This syntax, like 'DROP TABLE other_db.table_name', is useful for admin scripts that manage several databases at once.
Example: Deleting with Schema Contexts
DROP TABLE other_db.users;
Verifying Table Deletion
Running SHOW TABLES afterward confirms the table is really gone — a cheap, worthwhile check before assuming a destructive cleanup script actually did what you intended. It's also a good habit before assuming a migration or seed script's DROP statements actually ran as expected in production.
Example: Verifying Table Deletion
SHOW TABLES;
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: