Plsql_ Standard Delete mode delete/drop/truncate difference and comparison (concept)

Source: Internet
Author: User

2014-06-02 Baoxinjian

First, General

1. Delete

2. Drop

3. Truncate

4. Example: How to delete the non-conforming 99.99 million of the 100 million data, keep the rest

Second, the specific analysis

1. Delete/drop/truncate The difference between the deletion method

(1). Deleting Data and table definitions

Truncate and delete only delete data without deleting the structure of the table (definition)
The drop statement will delete the structure of the table that is dependent on the constraint (constrain), trigger (trigger), index (indexed); Stored procedures/functions that depend on the table are preserved, but become invalid states.
(2). DML or DDL

The DELETE statement is DML, which is placed in the rollback segement, which takes effect after the transaction is committed, and is triggered when the corresponding trigger is executed.
Truncate,drop is DDL, the operation takes effect immediately, the original data is not placed in the rollback segment and cannot be rolled back. Operation does not trigger trigger.
(3). Table Space

The DELETE statement does not affect the extent occupied by the table, and the high waterline (hi Watermark) remains in its original position.
The drop statement frees all the space occupied by the table
Truncate statement by default see space released to minextents extent unless reuse storage is used; Truncate will reset the high watermark (back to the beginning).
(4). Speed

General: drop> truncate > Delete
(5). Security

Be careful with drop and truncate, especially when there is no backup. Otherwise it's too late to cry
For use, to delete some data rows with delete, note the WHERE clause. The rollback segment should be large enough.
Want to delete the table, of course with drop
You want to keep the table and delete all the data. If it is unrelated to the transaction, use truncate. If it is related to a transaction, or if you want to trigger trigger, use Delete.

2. Example: How to delete the non-conforming 99.99 million of the 100 million data, keep the rest
(1). Create a table temporarily
Create table as Select from * Where
(2). Truncate The original table, re-create the modified table
(3). Transfer the data in the temporary table to the newly created original table
Pros: No need to consider issues such as index space for tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.