mysql database auto-increment id re-ordering from the two methods 1

When using mysql, table usually have an auto-incremented id field, but when we want to re-add the data table to clear the data in the hope id restarts counting from 1, with the following two methods are available:

Usually set auto-increment field methods:
add when you create the table:


create table table1(id int auto_increment primary key,...)

After you create a table added:


alter table table1 add id int auto_increment primary key field increment, must be set as primary key.


example


alter table tablename drop column id;
alter table tablename add id mediumint(8) not null primary key auto_increment first;

Method Two:

alter table tablename auto_increment=0

Guess you like

Origin www.cnblogs.com/HKROnline-SyncNavigator/p/11021008.html