Truncate and delete with no WHERE clause, and drop deletes data in the table
Different points:
1. Differentiate from deletion: Truncate and delete Delete only data do not delete the structure of the table (definition)
The DROP statement deletes the table's structure, dependent constraints (constrain), triggers (trigger), indexes (index); Stored procedures/functions that depend on the table are preserved, but become invalid states.
2. Differentiate from statement types: The DELETE statement is DML, which is placed in the rollback segement, which takes effect after the transaction is committed, and when the corresponding trigger is executed, it is triggered.
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. From the impact of the table space to distinguish: The DELETE statement does not affect the extent that the table occupies, and the high watermark (watermark) keeps the original position fixed
The drop statement frees up all of the space occupied by the table
The TRUNCATE statement by default frees up space to minextents extent unless the reuse storage is used, and truncate resets the high watermark (back to the beginning).
4. From the speed difference: Generally: drop> truncate > Delete
5. From Security considerations: Use drop and truncate carefully, especially when not backed up.
Use, to delete some data rows with delete, note the WHERE clause is taken. 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 has nothing to do with the transaction, use truncate. If it is related to a transaction, or if you want to trigger trigger, or delete.
If you are defragmenting the inside of the table, you can use truncate to keep up with reuse stroage and then re-import/Insert Data
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.