In MySQL delete record truncate and delete difference

Source: Internet
Author: User
Tags mysql delete mysql delete record rollback

Truncate usage

TRUNCATE [TABLE] Tbl_name

I want to delete all the records in the Friends table, you can use the following statement:

TRUNCATE TABLE friends;


Delete Usage

DELETE [low_priority] [QUICK] [IGNORE] from Tbl_name
[WHERE Where_definition]
[Order BY ...]
[LIMIT Row_count]

Multiple table syntax:

DELETE [low_priority] [QUICK] [IGNORE]
TBL_NAME[.*] [, tbl_name[.*] ...]
From Table_references
[WHERE Where_definition]

Example

DELETE from Somelog
WHERE user = ' Jcole '
ORDER BY Timestamp_column
LIMIT 1;

Delete rows from many tables at the same time, and search using other tables:

DELETE T1, t2 from T1, T2, T3 WHERE t1.id=t2.id and t2.id=t3.id;

Or:

DELETE from T1, T2 USING T1, t2, T3 WHERE t1.id=t2.id and t2.id=t3.id;

TRUNCATE command differs from DELETE command

1, truncate on all kinds of tables, whether large or small are very fast. If a rollback command delete is revoked, the truncate is not revoked.
2, truncate is a DDL language, like all other DDL languages, he will be implicitly submitted, not to truncate use rollback command.
3, TRUNCATE will reset the high-level line and all indexes. When you fully browse the entire table and index, the table after the truncate operation is much faster than the table after the delete operation.
4, TRUNCATE cannot trigger any delete trigger.
5, can not give anyone the right to empty other people's table.
6, when the table is emptied after the table and table index is reset to the initial size, and delete is not.
7, can not empty the parent table.

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.