Difference between truncate table and delete, truncatetable

Source: Internet
Author: User

Difference between truncate table and delete, truncatetable

Truncate table requires the drop table permission, which completely clears a table. Logically, the truncate table is the same as the delete table, or the drop table + create table is the same. Using truncate table to delete full table data is faster than deleting. The truncate table is used to clear data. rollback is not allowed and is not restricted by the foreign key constraints between tables. Truncate is a DDL statement and delete is a DML statement. The differences between the two are as follows: 1. truncate is a mail drop table + create table, which is much faster than deleting a row of data using delete, especially clearing Big Data Tables. 2. truncate is a type of implicit commit, so rollback is not allowed. 3. If the current table has foreign key constraints, the truncate table can clear all data in the table, without the foreign key constraints. 4. Use truncate table to set the auto-increment ID to zero, and delete will not. 5. When a partition table is used, the table is truncated to save the partition. That is, the data and index files are deleted and re-created, and the partition definition (. par) files are not affected. 6. The truncate table statement does not call the delete trigger.


Refer:

Http://dev.mysql.com/doc/refman/5.7/en/truncate-table.htmlhttp://dev.mysql.com/doc/refman/5.6/en/optimizing-innodb-ddl-operations.html


Truncate table and delete * from

There are two main differences. Truncate is the overall deletion, and delete is the one-by-one deletion. 2. truncate does not write server logs, and delete writes to server logs. This is why truncate is faster than delete. Therefore, the impact is as follows: 1. Truncate is 2 faster. Truncate does not activate trigger3. Truncate reset Identity

Question: What is the difference between truncate table and DELETE when deleting all records of the entire TABLE?

1. DELETE
・ DML Language
Rollback is supported.
Conditions can be deleted with conditions.

Delete from Table Name
WHERE condition

2. TRUNCATE TABLE
・ DDL Language
Rollback failed
By default, all table content is deleted.
The restore operation is faster than the delete operation.

Truncate table name

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.