Mysql tutorial-truncate and delete

Source: Internet
Author: User
Tags mysql tutorial

In short, the table id cleared with truncate will be from the new record, while the table cleared with delete will not continue with the original data record from the new record. Of course, the id here is self-increasing
========================================================== ========================================================== ==================
This article demonstrates how to use the truncate command and the difference between delete and truncate.
The following describes how to delete all data instances in a mysql table.
Truncate table mytable;
Use truncate to clear the table. The table id starts from 1.
Test the following example:
Create table 'user '(
'Id' int (11) not null auto_increment,
'Name' varchar (100) default null,
Primary key ('id '))
 
Insert several data records
Insert into user (name) values ('bob ');
Insert into user (name) values ('mark ');
Insert into user (name) values ('Alex ');
Insert into user (name) values ('julia ');
Check the data
Select * from user; the result is: id name 1 bob 2 mark
3 alex 4 julia
Take a look at the truncate instance
Truncate table user;
Insert a data entry
Insert into user (name) values ('bill ');
View results
Select * from user;
The result is: id name 1 bill

As you can see, the old record is deleted and the new id field 1 is obtained.

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.