Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to SQL Notes
Topic #110

DROP TABLE in SQL

DROP TABLE permanently deletes a table — structure and all its data. There's no built-in undo.

Syntax

DROP TABLE table_name;

-- Safer: won't error if it doesn't exist
DROP TABLE IF EXISTS table_name;

Example

DROP TABLE IF EXISTS temp_import_batch;

Practical Use Case

Removing temporary or staging tables after a data-load process finishes, or cleaning up a table created for testing that's no longer needed.

DROP vs TRUNCATE vs DELETE — Quick Preview

DROP TABLETRUNCATE TABLEDELETE
RemovesTable + data + structureAll rows, keeps structureRows matching a condition (or all)
Can use WHERE?NoNoYes
Undo with ROLLBACK?Usually not (DDL)Database-dependentYes (DML)

Full comparison in TRUNCATE TABLE.

Common Mistakes

  • Running DROP TABLE in production without a backup — this is one of the most common real-world disasters in SQL. Always confirm you're connected to the right database first.
  • Using DROP TABLE when you actually just wanted to empty it (that's TRUNCATE) or remove specific rows (that's DELETE)
  • Forgetting that dropping a table referenced by a foreign key in another table will fail (or cascade, depending on constraints) — check dependencies first

Interview Relevance

Q: "What happens to foreign key relationships when you drop a parent table?" Depends on the database and constraint setup — by default most databases block the drop if dependent rows/constraints exist, unless you explicitly cascade.

Practice Question

Write a statement that safely drops a table called old_logs_2023 without erroring if it's already gone.

Related SQL Notes

Want to go beyond the notes?

Join CodingNow's SQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →