What is the difference between a DELETE command and TRUNCATE command? | Eklavya Online

What is the difference between a DELETE command and TRUNCATE command?

DELETE command: DELETE command is used to delete rows from a table based on the condition that we provide in a WHERE clause.

  • DELETE command delete only those rows which are specified with the WHERE clause.
  • DELETE command can be rolled back.
  • DELETE command maintain a log, that’s why it is slow.
  • DELETE use row lock while performing DELETE function.

TRUNCATE command: TRUNCATE command is used to remove all rows (complete data) from a table. It is similar to the DELETE command with no WHERE clause.

  • The TRUNCATE command removes all the rows from the table.
  • The TRUNCATE command cannot be rolled back.
  • The TRUNCATE command doesn’t maintain a log. That’s why it is fast.
  • TRUNCATE use table log while performing the TRUNCATE function.