13 Votes

MySQL: Set Initial Value for AUTO INCREMENT

Question by Guest | Last update on 2021-07-02 | Created on 2015-03-02

In my MySQL database, I have set one column (ID) to AUTO_INCREMENT in order to increase the value of the ID by 1 with each data record that is inserted.

Apparently, MySQL starts counting at 1 by default. However, I would like to define another starting or initial value. Is there any possibility to define an arbitrary value for this?

ReplyPositiveNegative
2Best Answer2 Votes

First of all, you should create your table containing the AUTO_INCREMENT column. When the table is existing, you can use the following command to adjust the AUTO_INCREMENT value according to your needs:

ALTER TABLE tab AUTO_INCREMENT=1000

This sample would ensure, that the next inserted AUTO_INCREMENT-value of the table "tab" will be 1000.

PS: Of course, only in case of that this value has not been assigned yet.
Last update on 2021-07-02 | Created on 2015-03-04

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.