Difference between SQL truncate and delete

Source: Internet
Author: User
  1. The truncate table and the delete function without where are the same.All of the data in the table is deleted,However, truncate table is faster and consumes less logs.This is because the truncate table directly releases the data page and only records the release of the data page in the transaction log. The delete operation deletes the data page in one row, delete each record in the transaction log.
  2. Can we use truncate table instead of delete without where? It is not possible in the following situations:
    1. The truncate table cannot be used when the ID is to be retained, because the truncate table will reset the ID.
    2. The truncate table cannot be used when a trigger is required. It does not trigger the trigger.
    3. The truncate table cannot be used for tables referenced by the foreign key constraint (that is, the table where the primary key is located, not the table where the foreign key is located.
    4. The truncate table cannot be used for tables that participate in the index view. Note that the index view is not a common view.

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.