Many friends in MySQL feel the field auto_increment increment ID value it cannot be changed, in fact this realization is wrong, here MySQL Increment ID start value change and set.
The usual way to set an auto-increment field:
When you join the grid:
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 it to primary key.
Many times you want the ID of the data in the table not to start with 1, like QQ. ID starts 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;
The statement also applies to changing the ID of an existing table. For example, after you delete data in large batches, you want to return the ID from 654321 to 123456.
ALTER TABLE users auto_increment=123456;
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
MySQL Incremental ID Start value change method