What is difference between DELETE and TRUNCATE commands?


If you wish to remove rows basis on condition then we have to use DELETE command while truncate will remove all the rows from a table.

DELETE
  • Delete is a DML command
  • We can use the WHERE clause in the delete statement.
  • Delete statement delete specific rows if were the condition exist.
  • Delete command lock the row when executed, each row in the table is locked for deletion.
  • Delete operation are logged individually so delete activates the trigger.
  • Rollback is possible in delete.
  • Delete keeps a log so delete is slower than truncate.

TRUNCATE
  • Truncate is DDL command.
  • The truncate command removes all data from the table.
  • Truncate does not keep the logs so it fast then DELETE.
  • Truncate statement is not conditional mean we cannot use WHERE Clause in truncate statement.
  • Rollback is not possible.
  • Truncate reset the table to its empty state.




No comments:

Post a Comment

Please do not enter any spam link in the comment box.

NUnit : Introduction

There are several unit test tools in the market, but one of them is NUnit, the most popular tool for doing unit testing. So in this tutorial...