Difference Between Truncate and Delete in SQL


Difference Between Truncate and Delete in SQL:


Basically Delete and Truncate commands are used to delete the table data from database. TRUNCATE is a DDL command where as DELETE is the DML command.

Truncate Syntax:    

TRUNCATE TABLE tablename;

Delete syntax  :  

DELETE FROM tablename WHERE Condition;

TRUNCATE don't have the where condition so entire data will be deleted. But DELETE have the WHERE condition so we can delete specific data.

Below are the differences between truncate and delete

1. TRUNCATE is a DDL command where as DELETE is DML command.

2. TRUNCATE command delete's the entire table data where as DELETE also removes all the data But we can restrict using where condition.

3. TRUNCATE is DDL command So By-default system will commit the query where as DELETE don't have auto commit. So We have to commit explicitly.

4. We can't rollback the data after TRUNCATE.  But DELETE have rollback option.

5. Performance wise, TRUNCATE is faster than the DELETE option where as DELETE also have high performance but less compared to truncate.


                                                          Thank You




Comments