Many friends in MySQL think that the field auto_increment type self-increment ID value can not be modified, in fact, this understanding is wrong, the following describes the MySQL self-increment ID starting value modification and setting method.
The usual way to set the self-increment field:
Add when creating a table:
CREATE TABLE table1 (ID int auto_increment PRIMARY key,...)
After creating the table, add:
ALTER TABLE table1 Add ID int auto_increment primary key self-increment field, be sure to set to primary key.
Many times you want the ID of the data in the table not starting from 1, like QQ, ID starting from 10000
The code is as follows:
Add when creating a table:
CREATE TABLE ' orders ' ( ' order_num ' int (one) not null auto_increment, ' order_date ' datetime NOT NULL, ' Cust_ ID ' int (one) not NULL, PRIMARY key (' Order_num '), key ' fk_orders_customers ' (' cust_id '), CONSTRAINT ' FK_Orders_Customers ' FOREIGN KEY (' cust_id ') REFERENCES ' customers ' (' cust_id ') on the DELETE CASCADE on UPDATE CASCADE) Engin E=innodb auto_increment=10000 DEFAULT Charset=utf8;
After creating the table, add:
ALTER TABLE users auto_increment=10000;
And the statement also applies to modify the ID of an existing table, such as large batches of deleted data, the ID from 654321 to 123456 start
ALTER TABLE users auto_increment=123456;
MySQL self-increment ID Start Value modification method