MySQL Tutorial clear table truncate and delete differences
This article demonstrates how to use the truncate command, and the difference between delete and truncate
Here's a list of all the data instances that are deleted from a MySQL table.
TRUNCATE TABLE mytable;
Using Truncate to empty the table, the table ID starts at 1.
The following test instance
CREATE table ' user ' (
' id ' int (one) not NULL auto_increment,
' Name ' varchar (+) default NULL,
Primary KEY (' ID '))
Insert a few data
Insert into user (name) VALUES (' Bob ');
Insert into user (name) values (' mark ');
Insert into user (name) VALUES (' Alex ');
Insert into user (name) VALUES (' Julia ');
Look at the data
select * from user; The result is:id name & nbsp; 1 bob 2 Mark
3 Alex 4 Julia
Take a look at the truncate example
TRUNCATE TABLE user;
Insert a piece of data
Insert into user (name) VALUES (' Bill ');
View Results
select * from user;
The result Is:id name 1 bill
As you can see the old records are deleted in addition to the new Get ID field 1