TRUNCATE TABLE and delete

Source: Internet
Author: User
Delete table and TRUNCATE TABLE

Use the DELETE statement to delete the general syntax format of the data:

Delete [from]

{table_name, view_name}

[Where<search_condition>]

Delete all row data in the XS table

Delete XS

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

Truncate

The TRUNCATE TABLE statement deletes all the data in the specified table, so it is also known as the Purge table data statement, which is generally formatted as follows

TRUNCATE TABLE name

Because the TRUNCATE statement will delete all the data in the table and cannot be recovered, you must use caution when using it.

All rows in the specified table are deleted using TRUNCATE TABLE, but the structure of the table and its columns, constraints, indexes, and so on, remain the same, and the count value used for the new row identity is reset to the initial value of the column. If you want to preserve the identity count value, use the DELETE statement.

TRUNCATE table executes faster than the delete block and uses less system and transaction log resources. The DELETE statement deletes one row at a time and records an entry in the transaction log for each row that is deleted. Instead, truncate table deletes data by releasing the data page used to store the table data, and records the release of the page only in the transaction log.

For a table that has a foreign key constraint reference, you cannot use TRUNCATE table to delete the data, but you should use the DELETE statement for the cloth bag where clause. Also, TRUNCATE TABLE cannot be used for tables that participate in indexed views.

From

Http://www.cnblogs.com/herbert/archive/2010/07/06/1772135.html

TRUNCATE TABLE and delete

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.