Similarities and differences between truncate, delete, and drop

Source: Internet
Author: User

Similarities and differences between truncate, delete, and drop

Note: The delete statements without the WHERE clause share the same points: truncate and delete without the WHERE clause, and drop will delete the data differences in the Table: 1. the truncate and delete statements that only delete data and do not delete the table's structure (Definition) Drop statement will delete the constraints (constrain), triggers (triggers), and indexes (indexes) that the table structure is dependent on ); 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 put into the rollback segement and takes effect only after the transaction is committed. If a trigger exists, it is triggered during execution. truncate, drop is DDL, and the operation takes effect immediately. The original data is not placed in rollback segment and cannot be rolled back. trigger is not triggered. 3. the delete statement does not affect the extent and high watermark used by the table) keep the original location unchanged. Obviously, the drop statement will release all the space occupied by the table. The truncate statement defaults to the minextents extent, unless you use reuse storage; truncate will reset the high water line (back to the beginning ). 4. speed. Generally, drop> truncate> Delete 5. security: Use drop and truncate with caution, especially when no backup is available. otherwise, you will not be able to use it when you cry. If you want to delete some data rows, use Delete. Note that the WHERE clause is included. the rollback segment must be large enough. to delete a table, use drop to retain the table and delete all data. if it is irrelevant to the transaction, use truncate. if it is related to the transaction or you want to trigger the trigger, delete is used. if you want to organize fragments in the table, you can use truncate to keep up with the 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.