Difference between DELETE and TRUNCATE

DELETE is a DML(Data Manipulation Language) command and is used when we specify the row(tuple) that we want to remove or delete from the table or relation. The DELETE command can contain a WHERE clause. If WHERE clause is used with DELETE command then it remove or delete only those rows(tuple) that satisfy the condition otherwise by default it removes all the tuples(rows) from the table.

Syntax of DELETE command :

WHERE condition; 

TRUNCATE is a DDL(Data Definition Language) command and is used to delete all the rows or tuples from a table. Unlike the DELETE command, TRUNCATE command does not contain a WHERE clause. In the TRUNCATE command, the transaction log for each deleted data page is recorded. Unlike the DELETE command, the TRUNCATE command is fast and we can’t rollback the data after using the TRUNCATE command.

Syntax of TRUNCATE command:-


Let’s see the difference between DELETE and TRUNCATE command:-

S.NO Delete Truncate
1. The DELETE command is used to delete specified rows(one or more). While this command is used to delete all the rows from a table.
2. It is a DML(Data Manipulation Language) command. While it is a DDL(Data Definition Language) command.
3. There may be WHERE clause in DELETE command in order to filter the records. While there may not be WHERE clause in TRUNCATE command.
4. In the DELETE command, a tuple is locked before removing it. While in this command, data page is locked before removing the table data.
5. We can rollback the data even after using DELETE command. While in this command, we can’t rollback.
6. DELETE command is slower than TRUNCATE command. While TRUNCATE command is faster than DELETE command.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : MKS075