Differences between Truncate and delete in mysql clearing tables this article demonstrates how to use the TRUNCATE command and the differences between delete and truncate. The following describes how to delete all data instances in a mysql table.
What is the difference between clearing the table truncate and delete in the mysql tutorial?
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.