Understanding and summary of the sql delete, truncate, drop the

Regarding the article, this article is to find data compilation from the Internet, to facilitate future memory

 

delete command to delete the data can be recovered,

truncate command deletes the data is not restored, the kind of full deleted

drop command to delete the data unrecoverable, even the kind of table structure are deleted

 

Same point

truncate and delete without a where clause, and the data will be deleted in the drop table.

difference:

1. truncate and delete data to delete only the structure of the table are not deleted, drop statement removes the table structure is dependent constraints (constrain), the trigger (trigger), an index (index); dependent table stored in the procedure / function will reservations, but it becomes invalid state.

2.delete statement is dml, this action will put rollback segement, the only take effect after the transaction commits; if there is a corresponding trigger, when the execution will be triggered. truncate, drop is ddl, operating with immediate effect, the original data is not put rollback segment can not be rolled back. Operation does not trigger the trigger.

3.delete statements do not affect the table occupied by the extent, high waterline (high watermark) to maintain the original position does not move. Obviously statement drop table space occupied by the release of all. See truncate statement released to the default space minextents a extent, unless reuse storage; truncate will reset the high water line (back to the beginning).

4. Speed: General: drop> truncate> delete.

5. Security: Be careful using the drop and truncate, in particular when there is no backup. Otherwise too late to cry.

Use on the part of the data you want to delete the row with delete, to bring attention to the where clause. Rollback segments should be large enough.

I want to delete the table, of course, with a drop.

I want to keep all the data tables will be deleted. If the transaction and has nothing to do with truncate to. If and matters relating to, or want to trigger the trigger, or a delete.

If it is inside finishing table fragmentation, you can truncate keep reuse stroage, reintroduced into / insert the data.

Guess you like

Origin www.cnblogs.com/Yogurt-harry/p/11140002.html