About delete mysql table

 

1. delete from 表名

The most familiar with the delete method, such as: delete from course, which will delete all records in the course.

Table structure is not deleted, the space will not be released, if the increment is the primary key, then insert the data again, id does not start from 1, but based on the maximum id + 1 previously deleted.

It can be achieved through a transaction rollback and restore data.

 

2. truncate 表名

As will be clear the data in the table, do not delete the table structure. Will free up space, id will start from 1 (if set increment).

 

3. drop table

Delete the entire table, the data structures are deleted.

 

delete and truncate the difference between:

 1. Affairs and revocation: delete subject to transaction management, available rollback rollback revoked; truncate can not.

 2. Efficiency: the efficiency of either delete or delete operation after the subject of efficiency, truncate higher than delete. truncate table regardless of size, are quickly; delete delete it is progressive, so the execution is slower and more data, the slower execution.

               After truncate, index tables and table resizing, not delete, delete the table after the operation is slower than truncate.

Guess you like

Origin www.cnblogs.com/tiny-me/p/11772988.html