← Back to MySQL Course | Chapter 2: Databases & Tables | Lesson 5 of 7

DROP TABLE

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

sql
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

sql
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

sql
DROP TABLE IF EXISTS users, orders, logs;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

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

sql
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

sql
SHOW TABLES;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.