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.