Oracle uses TRUNCATE table to delete all rows

Source: Internet
Author: User

To remove all rows from a table, the TRUNCATE table statement is a quick and efficient method. TRUNCATE TABLE is similar to a DELETE statement that does not contain a WHERE clause. However, TRUNCATE TABLE is faster and uses fewer system resources and transaction log resources.

TRUNCATE TABLE has the following advantages over the DELETE statement:

  • Less transaction log space is used.

    The DELETE statement deletes one row at a time and records an item in the transaction log for each row that is deleted. TRUNCATE table deletes data by releasing the data page used to store the table data, and only the page release is recorded in the transaction log.

  • The locks used are usually less.

    When you execute a DELETE statement by using a row lock, the rows in the table are locked for deletion. TRUNCATE table always locks tables and pages instead of locking rows.

  • Without exception, no pages will be left in the table.

    After the DELETE statement is executed, the table will still contain empty pages. For example, you must use at least one exclusive (lck_m_x) table lock to free up empty tables in the heap. If you do not use a table lock when you perform a delete operation, many empty pages will be included in the table (heap). For indexes, the delete leaves some empty pages, although these pages are released quickly through the background cleanup process.

As with the DELETE statement, the definition of a table emptied with TRUNCATE table is persisted with its index and other associated objects in the database. If the table contains an identity column, the counter of the column is reset to the seed value defined by the column. If no seed is defined, the default value of 1 is used. To preserve the identity counter, use DELETE.

Oracle uses TRUNCATE table to delete all rows

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.