Pages

10 January 2016

SQL - DELETE and TRUNCATE

SQL- DELETE and TRUNCATE

Major difference between DELETE and TRUNCATE are as follows:

          DELETE                                                            TRUNCATE
1. DELETE is  DML Command                   1. TRUNCATE is DDL Command
2. WHERE clause can be used                  2. WHERE clause cannot be used
    along with DELETE.                                   along with TRUNCATE
3. It removes data from the table                 3. It removes all data from the table
   based on WHERE clause.                        
4. It puts lock on a row .                             4. It puts locks on a table
5. It is slower as it keeps log.                      5. It is faster as it does not keep log.
6. Space is not released.                            6. Space is released.
7.Syntax:                                                  7.Syntax:
   DELETE FROM table_name                     TRUNCATE TABLE table_name
   [WHERE condition]


No comments:

Post a Comment