1. DELETE :
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 :
DELETE FROM TableName WHERE condition;
2. TRUNCATE :
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:-
TRUNCATE TABLE TableName;
Let’s see the difference between DELETE and TRUNCATE command:-
|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.
- Difference between DELETE, DROP and TRUNCATE
- Difference between DROP and TRUNCATE in SQL
- Difference between DELETE and DROP in SQL
- SQL | DROP, TRUNCATE
- SQL | DELETE Statement
- PHP | MySQL Delete Query
- new vs malloc() and free() vs delete in C++
- Neo4j Delete Node
- Delete Operation in B-Tree
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- Difference between IBM DB2 and MS SQL
- Difference between MP4 and MP3
- Difference between USB 2.0 and USB 3.0
- Difference between RAM and ROM
- Difference between IoE and IoT
- Difference between Tor and VPN
- Difference between DAS and NAS
- Difference between JSP and ASP
- Difference between PNG and GIF
- Difference between DML and TCL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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