Back to community
Computer ScienceClass 12 (CBSE) Resolved

What is the difference between DELETE, TRUNCATE and DROP in SQL?

These three commands all seem to remove data and I always confuse them in theory papers. Can someone explain clearly what each one actually removes?

TuitionsInIndia Study Desk 17 135d ago
Need help with Computer Science? Browse tutor profiles and check whether they teach your subject and class.

1 answer

Accepted answer
3

They differ in what they remove and whether the structure survives. DELETE removes rows, and you can use a WHERE clause to delete only some rows; the table structure stays. It is a DML command and can be rolled back. TRUNCATE removes all rows at once but keeps the empty table structure; it is faster than DELETE and cannot use WHERE. DROP removes the entire table, including its structure, columns and data, so the table no longer exists in the database. Quick way to remember: DELETE picks rows, TRUNCATE empties the table, DROP destroys the table. For exams, note that DELETE is DML while TRUNCATE and DROP are DDL commands.

TuitionsInIndia Study DeskEditorial
Reviewed answer · 135d ago

Sign in as a tutor to answer this doubt.