1.

Explain the difference between the DELETE and TRUNCATE command in a DBMS.

Answer»

DELETE command: this command is needed to delete rows from a table based on the condition provided by the WHERE clause.

  • It deletes only the rows which are specified by the WHERE clause.
  • It can be rolled back if required.
  • It maintains a log to lock the ROW of the table before deleting it and hence it’s slow.

TRUNCATE command: this command is needed to remove complete data from a table in a database. It is like a DELETE command which has no WHERE clause.

  • It removes complete data from a table in a database.
  • It can be rolled back even if required. ( truncate can be rolled back in some databases depending on their VERSION but it can be TRICKY and can lead to data loss). CHECK this LINK for more details
  • It doesn’t maintain a log and deletes the whole table at once and hence it’s fast.


Discussion

No Comment Found