Showing posts with label Difference between SQL DELETE and TRUNCATE Statement. Show all posts
Showing posts with label Difference between SQL DELETE and TRUNCATE Statement. Show all posts

Sunday, 7 May 2017

Difference between SQL DELETE and TRUNCATE Statement

In this post, I will explain the Difference between SQL Delete and Truncate Statement.

In SQL, there are different ways to delete rows from a table. We can use Delete Statement or Truncate Statement to delete rows.

Here are some important differences between delete and truncate statement:
1.  Delete statement is used to delete a single or multiple rows from a table, we can use where clause with delete statement to delete selected row(s). Truncate statement is used to remove all rows from a table, it performs the same function as a Delete statement without a Where clause.
2. Where clause with delete statement is optional. Truncate statement is without where clause.
3. Delete operation on a table will not reset the identity column counter. Truncate operation on a table resets identity column counter.

Example -
Delete Statement
DELETE FROM tbl_Employee WHERE Id = 10
Truncate Statement
TRUNCATE TABLE tbl_Employee