Difference between DELETE, TRUNCATE, and DROP
Difference between DELETE, TRUNCATE, and DROP
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
In SQL, the three most commonly used commands for this purpose are:
Although all three remove data, they work in very different ways.
Understanding the difference is very important for database developers, DBAs, and interview preparation.
1. DELETE Command
Syntax
Features
Example
This will remove all rows but table structure remains.
2. TRUNCATE Command
Syntax
Features
Example
Table remains, data removed.
3. DROP Command
Syntax
Features
Example
Table no longer exists.
Main Difference Table
When to Use DELETE
Use DELETE when:
Example:
When to Use TRUNCATE
Use TRUNCATE when:
Example:
When to Use DROP
Use DROP when:
Example:
Interview Question
Difference between DELETE and TRUNCATE?
Answer:
Conclusion
DELETE, TRUNCATE, and DROP are very important SQL commands.
Every SQL developer must know the difference.