What is the difference between delete drop truncate?

All three SQL commands can delete data from a database table, but there are several differences between them:

  1. DELETE: Delete rows from the table, and return the number and content of deleted rows. The deleted operation can be controlled by the WHERE clause, and ROLLBACK can be used to undo the operation.
  2. DROP: Deletes the entire table structure and all data in the table, does not return anything and cannot roll back the operation.
  3. TRUNCATE: Deletes all data in the entire table, but retains the table's structural definition, does not return anything, cannot roll back the operation, and is usually faster than the DELETE operation.

Therefore, DROP and TRUNCATE can be regarded as two ways to clear the table at one time, while DELETE is more suitable for deleting certain rows and needs to specify conditions at the same time. It should be noted that these three commands need to be used with caution, because they involve permanent changes to data.

Guess you like

Origin blog.csdn.net/qq_45800977/article/details/130197652