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.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Neo4j Delete Node
- new vs malloc() and free() vs delete in C++
- PHP | MySQL Delete Query
- Delete Operation in B-Tree
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- Difference Between SEO and SEM
- Difference between DFD and ERD
- Difference between OOP and POP
- Difference between PCA VS t-SNE
- What is the difference between GUI and CUI?
- Difference between LAN and MAN
- Difference between IBM DB2 and MS SQL
- Difference between DVD-R and DVD-RW
- Difference between MP4 and MP3
- Difference between RPC and RMI
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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