Home >Database >Mysql Tutorial >How Can I Change the Starting Number for Auto-Increment in MySQL?
Modifing Auto-Increment Starting Number
In MySQL, it is possible to modify the initial value for auto-increment columns. This capability allows you to set a specific number as the starting point for generating unique keys.
Query for Changing Auto-Increment Starting Number
To alter the auto-increment value, use the following query syntax:
ALTER TABLE table_name AUTO_INCREMENT = new_value;
For instance, the query below sets the auto_increment value to 5 for the "tbl" table:
ALTER TABLE tbl AUTO_INCREMENT = 5;
Result
After executing the query, subsequent INSERT operations into the "tbl" table will generate auto-increment values starting from 5. It is important to note that existing values in the auto-increment column will not be affected.
Additional Information
If you attempt to use a starting value that is equal to or less than the current maximum value in the column, the auto-increment will resume from the current maximum value. For detailed information on using ALTER TABLE to modify table structures in MySQL, please refer to the official documentation.
The above is the detailed content of How Can I Change the Starting Number for Auto-Increment in MySQL?. For more information, please follow other related articles on the PHP Chinese website!