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 CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between DELETE, DROP and TRUNCATE
- Difference between DROP and TRUNCATE in SQL
- SQL | DROP, TRUNCATE
- TRUNCATE() Function in MySQL
- Difference between DELETE and DROP in SQL
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- new vs malloc() and free() vs delete in C++
- Delete Operation in B-Tree
- SQL | DELETE Statement
- Delete statement in MS SQL Server
- PHP | MySQL Delete Query
- Neo4j Delete Node
- Delete Action in MS SQL Server
- Delete Database in MS SQL Server
- Delete Duplicates in MS SQL Server
- Difference between Stop and Wait, GoBackN and Selective Repeat
- Difference between Stop and Wait protocol and Sliding Window protocol
- Similarities and Difference between Java and C++
- Difference between Yaacomo and and XAP
- Difference between VoIP and and POTS
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