Mysql auto-increment ID start value modification method, mysql modification method
Many friends in mysql think that the field AUTO_INCREMENT Type Auto-increment ID value cannot be modified. In fact, this is an incorrect understanding. The following describes how to modify and set the starting value of mysql auto-increment ID.
The following describes how to set an auto-increment field:
Add the following when creating a table:
create table table1(id int auto_increment primary key,...)
After creating a table, add:
Alter table table1 add id int auto_increment primary key auto-increment field, must be set to primary key.
In many cases, it is expected that the table data IDs do not start from 1, such as qq, and IDs start from 10000.
The Code is as follows:
Add the following when creating a table:
CREATE TABLE `orders` ( `order_num` int(11) NOT NULL auto_increment, `order_date` datetime NOT NULL, `cust_id` int(11) 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 DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;
After creating a table, add:
alter table users AUTO_INCREMENT=10000;
This statement can also be used to modify the id of an existing table. For example, if you want to return the id from 654321 to 123456 after deleting a large number of data
alter table users AUTO_INCREMENT=123456;