Related usage of SQL database Truncate

The usage of Truncate in the database:
This is to delete all data in the table. The
syntax is Truncate Table tablename
. The difference between it and delete is that
1 delete can be deleted conditionally and truncate is to delete all data and can reset the automatic growth column.
2 delete can be rolledback( Rollback) and truncate cannot be
3. Truncate deletes faster than delete
. In addition to these two, there is also drop
in terms of speed. In terms of speed, drop>truncate>delete,
only delete will trigger trigger while the other two will not
delete. It belongs to DML The other two belong to the DLL
mysterious code: https://blog.csdn.net/ws0513/article/details/49980547Summary
:

1. In terms of speed, in general, drop > truncate > delete.

2. Be careful when using drop and truncate. Although it can be restored, you should be cautious in order to reduce trouble.

3. If you want to delete some data, use delete, pay attention to bring the where clause, and the rollback segment should be large enough;

If you want to delete the table, of course, use drop;

If you want to keep the table and delete all the data, if it has nothing to do with the transaction, just use truncate;

If it is related to a transaction, or if you want to trigger a trigger, use delete;

If you are sorting the fragments inside the table, you can use truncate to keep up with reuse stroage, and then re-import/insert dataEND
;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325274184&siteId=291194637