Detailed explanation of mysql clear table command-delete&truncate

MySQL can use delete or truncate to clear the table:

1. delete

1. Use grammar

delete from table_name;

2. Usage examples

DELETE FROM `order`;

2. Truncate clear

1. Use grammar

truncate table table_name;

2. Usage examples

TRUNCATE TABLE `order`;

3. The difference between delete&truncate

1. Use delete to clear the records in the table. The content ID will still be established from the ID of the deletion point, instead of starting from 1. Truncate is equivalent to retaining the structure of the table and re-creating a new same table. The effect of delete is a bit like deleting all the records in the mysql table one by one until the deletion is complete.

2. In terms of efficiency, truncate is faster than delete. However, the mysql log will not be recorded after truncate is deleted, and the data cannot be restored.

Guess you like

Origin blog.csdn.net/c851204293/article/details/123223724