iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

SQL DROP TABLE

DROP TABLE removes a table and all its rows in one shot. No undo unless you're inside a transaction.

Basic form

SQL
DROP TABLE customers;

If exists

SQL
DROP TABLE IF EXISTS customers;

Cascade — drop dependents too

If other tables have foreign keys pointing at this table, the drop fails. To force it:

SQL
DROP TABLE customers CASCADE;        -- PostgreSQL
-- MySQL: drop the FKs / dependent tables first.

DROP vs TRUNCATE vs DELETE

StatementRemovesReusable table after?
DROP TABLE tThe table and its dataNo — table is gone
TRUNCATE tAll rows, fast, resets auto-incrementYes
DELETE FROM tSelected rows (or all)Yes

Transactions can save you

PostgreSQL and SQL Server allow DROP TABLE inside a transaction — you can ROLLBACK the drop. MySQL's MyISAM and most DDL does not roll back. Check before you trust it.

Tip: Before a destructive drop in production, rename the table first: ALTER TABLE customers RENAME TO customers_to_drop_20260606;. Wait a week, then drop. If anything broke, just rename back.

Example

Example
DROP TABLE customers;
Try it Yourself »

Exercise

Make the drop safe even when the table is missing.

DROP TABLE EXISTS customers;

Test yourself

Q1. DROP TABLE differs from TRUNCATE because…
Q2. Postgres lets you drop dependents with…
Q3. A safer prod pattern before dropping a table is…

Discussion

Loading…