What is the difference between DELETE and TRUNCATE in SQL ?

 Posted by Bharathi Cherukuri on 2/13/2012 | Category: Sql Server Interview questions | Views: 4187 | Points: 40
Answer:

Using TRUNCATE, we cannot restore the deleted data.

Syntax:

TRUNCATE TABLE table_name;


Example:

To delete all the rows from employee table, the query would be like,

TRUNCATE TABLE employee; 


Unlike using DELETE, we can restore the data, as the physical data will not get deleted.

Syntax:

DELETE FROM table_name [WHERE condition]; 


Example:

To delete an employee with id 100 from the employee table, the sql delete query would be like,

DELETE FROM employee WHERE id = 100;


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Blessyjees on: 2/17/2012 | Points: 10
Hi,

To delete rows using truncate, the identity column will reset , but not reset when using delete

Login to post response