Oracle path (2)-truncate, delete, drop

Source: Internet
Author: User

Similarities and differences between truncate, delete, and drop

Note: The delete statement is a delete statement without the WHERE clause.

Similarities:

Truncate, delete without WHERE clause, and drop both delete table data.

Differences:

1. truncate and delete: delete only data. Do not delete the table structure (Definition)

The drop statement deletes the constrain, trigger, and index constraints on the table structure );

Stored Procedures/functions dependent on the table will be retained, but will change to the invalid state.

2. The delete statement is DML, which is placed in the rollback segement and takes effect only after the transaction is committed;

If a trigger exists, the trigger is triggered during execution. truncate. Drop is DDL, and the operation takes effect immediately,

The original data is not stored in rollback segment and cannot be rolled back. Trigger is not triggered.

3. The delete statement does not affect the extent used by the table, and the high watermark keeps the original position unchanged.

Obviously, the drop statement releases all the space occupied by the table. The truncate statement is released to the minextents extent by default,

Unless reuse storage is used; truncate will reset the high water line (back to the beginning ).

4. Speed, in general: Drop>; truncate>; Delete

5. Security: Be careful when using drop and truncate, especially when there is no backup. Otherwise, you will not be able to use them when crying,

To delete some data rows, use Delete. Note that the WHERE clause must be included. The rollback segment must be large enough. To delete a table,

Of course, you can use drop to delete all the data that you want to keep the table. If it is irrelevant to the transaction, use truncate.

If it is related to the transaction, or you want to trigger the trigger, or use Delete. If it is to sort the fragments in the table,

You can use truncate to keep up with reuse Stroage, and then re-import/insert data.

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.