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

DROP TABLE

DROP TABLE is like removing an entire chart from the wall, including all the rows of information written on it and the chart itself.
Syntax
sql
DROP TABLE [IF EXISTS] table_name;

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.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running DROP TABLE users; without a backup, since the table and all its rows are gone and cannot be rolled back.
  2. Dropping a table that another table references with a foreign key, which fails until the constraint is removed.
  3. Using DROP TABLE when only the rows should go, when TRUNCATE or DELETE would keep the table structure.
🔒

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.