[Reprinted] the difference between the delete table and the truncate table is tabletruncate.

Source: Internet
Author: User

[Reprinted] the difference between the delete table and the truncate table is tabletruncate.

The general syntax format for deleting data using the delete statement:

Delete [from]

{Table_name, view_name}

[Where]

Delete all row data in the XS table

Delete XS

After the execution, we found that the data in the XS table was deleted, but the table structure was still there.

Truncate

The truncate table statement deletes all the data in the specified table. Therefore, it is also called the clear table data statement. The general format is as follows:

Truncate table name

Because the truncate statement will delete all data in the table and cannot be recovered, you must be very careful when using it.

The truncate table is used to delete all rows in the specified table, but the table structure, its columns, constraints, and indexes remain unchanged. The Count value used for the new row ID is reset to the initial value of the column. If you want to retain the ID Count value, use the DELETE statement.

The truncate table is faster than the DELETE block and uses less system and transaction log resources. The DELETE statement deletes a row at a time and records one row in the transaction log. The truncate table deletes data by releasing the data pages used to store TABLE data, and only records the release of pages in transaction logs.

For tables referenced by foreign key constraints, you cannot use truncate table to DELETE data. Instead, you should use the DELETE statement of the WHERE clause of the bag. In addition, the truncate table cannot be used for tables that participate in the index view.

Related Article

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.