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?

Asked by Ananya Sharma 15 45d ago
Need a Computer Science tutor? Browse verified Computer Science tutors near you.

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.

D
Deepak Kulkarni
355 pts· 45d ago

Sign in as a tutor to answer this doubt.