What is the difference between deleting a table and truncating a table command?

Source: Internet
Author: User

What is the difference between deleting a table and truncating a table command.

This issue was submitted on November 23, 2004

Table deletions include table definitions and associated objects (rules, indexes, approx, triggers, primary keys, and so on). Obviously, once the table is deleted, all rows of data contained in the table are deleted together.

The truncate <table> command only deletes all data rows in the table. The structure of the table and all the indexes still persist until you enter the command to delete the table (as described above). Rules, defaults, constraints that are bound to columns continue to bind, and triggers still work.

Truncating the table command also reclaims the allocation page for all indexes.

Truncating a table's execution speed is the same as the delete command without a WHERE clause, even faster than it does. Delete Deletes one row of data at a time, and each row of deleted data is logged as a transaction, while the TRUNCATE (truncated) table reclaims the entire data page, recording only a small number of log entries. Delete (delete) and truncate (truncation) reclaim the space occupied by the data and the associated indexes. Only the owner of the table can truncate the table.

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.