oracle - the difference delete truncate drop

One, delete

. 1, is the DML delete, delete operation is performed, each row deleted from the table, and simultaneously records the row delete operation for rollback (ROLLBACK) and redo operations in the redo and undo table space, but Note that the table space is large enough, you need to manually submit (commit) operations to take effect, you can undo the operation by the rollback.

2, delete to delete the table according to the conditions to meet the conditions of the data, if you do not specify the where clause, then delete all records in the table.

3, delete statement does not affect the table occupied by the extent, high waterline (high watermark) remain unchanged original position.

二、truncate

1, truncate is DDL, implicitly submit, therefore, can not be rolled back, not fire the trigger.

2, truncate will delete all records in the table, and will be re-set the high-water line and all the indexes, by default minextents free up space to a extent, unless reuse storage ,. The log does not record, so the execution is very fast, but can not be undone by rollback operation (if accidentally truncate a table out, also can be restored, but can not rollback to restore).

3, the foreign key for the table (ForeignKey) constraint references can not be used truncate table, and use the delete statement without a where clause.

4, truncatetable not be used to participate in a table indexed view.

Three, drop

1, drop a DDL, implicitly submit, therefore, can not be rolled back, not fire the trigger.

2, drop statement to delete all table structure and data, and the release of all the space occupied by the table.

3, drop statement removes a table structure-dependent constraints, triggers, indexes, depending on the table stored procedure / function will be retained, but becomes invalid state.

 

to sum up:

1, the speed, in general, drop> truncate> delete.

 2, be sure to pay attention to when using drop and truncate, although can be restored, but in order to reduce trouble, still have to be careful.

3, if you want to delete some data delete, to bring attention to the where clause, rollback segments should be large enough; if you want to delete the table, of course, with a drop; If you want to keep all the data tables will be deleted, and if a transaction has nothing to do with truncate you can; and if matters relating to, or want to trigger the trigger, or use the delete; if the table is finishing debris inside, you can keep up with the truncate reuse stroage, and then re-import / insert data.

 

 

Guess you like

Origin www.cnblogs.com/kingle-study/p/10955595.html