In Oracle delete, truncate and drop

In Oracle delete, and TRUNCATE drop
(. 1) during the deletion of the delete statement is that each row deleted from the table, and simultaneously deletes the row
         as a transaction record saved for rollback operation performed in the log. truncate once from the table
         to delete all the data is not a separate delete operation to save logged records, delete rows can not be restored.
         And does not activate delete trigger associated with a table in the process deleted. Fast execution speed.

(2) table and index space occupied.
         When the table is truncate, the table and index space occupied will return to its original size,
         the Delete operation will not reduce the space occupied by the table or index.
         drop statement table space occupied by the fully relieved.

(3) In general, drop> truncate> delete

(4) Application.
         1) trcucate only on the table;         
         2) may be a table and view Delete

(5) truncate and delete only delete data, drop the entire table is deleted (structure and data).

(6) truncate delete without a where: Delete only data, without deleting the table structure (as defined)
         drop statement removes the table structure is dependent constraints (constrain), the trigger (Trigger) index (index);
         dependent in the table stored procedure / function will be retained, but its status changes: invalid.

(7) delete statement DML (data maintain Language), this operation will be placed in the rollback segment,
         take effect until the transaction commits. If there is a corresponding tigger, when the execution will be triggered.

(8) truncate, drop a DLL (data define language), operations with immediate effect, the original data is not placed in the rollback segment, can not roll back

(9) In the absence of a backup, the prudent use of drop and truncate. To remove some rows of data using delete and pay much attention to where the constraints of influence.
         Rollback segments should be large enough. To delete a table with drop; if you want to retain the table and delete the data in the table, if unrelated to the transaction, with truncate can be realized.
         If and matters relating to, or want to trigger trigger, or a delete.

(10) truncate table table name is fast and efficient, because:
          TRUNCATE to delete the Table statement without a where clause are functionally the same: both remove all rows in the table.
          But truncate table is faster than delete speed, and fewer system and transaction log resources used. Every delete statement delete a row,
          and record an entry for each row deleted in the transaction log. truncate table to delete data stored in the page table by releasing the data used for data,
          and only releases the page is recorded in the transaction log.

(11) truncate table to delete all the rows in the table, but the table structure and its columns, constraints, indexes and so on remain unchanged. New line count value reseeded identification used for that column.
          If you want to keep the identity count value, use the delete. If you want to remove table definition and its data, use the drop table statement.

(12) to the table referenced by the foreign key constraints, you can not use truncate table, and use the delete statement without a where clause.
          Since truncate table is not recorded in the log, it can not activate the trigger.

A, delete
       . 1, is the DML delete, delete operation is performed, each row deleted from the table, and simultaneously records the row delete operation for the redo and undo tablespace
             rollback (ROLLBACK) and redo , but pay attention to 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 extent occupied by the table (size limit), high waterline (high watermark) remain unchanged original position.

Two, 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 you accidentally put a table
            truncate 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, truncate table can not be used involved table index 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.

Summary:
       1, in 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;
            if and 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/lxm11/p/11989487.html