Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Can you specify the starting index?

Tags:

indexing

mysql

Is it possible in MySQL to set the starting value of a primary key index, so it starts at say 15 instead of 1?

A quick hack would be to write a loop of 14 junk entries, add the correct data then delete the first 14 entries but I would be interested to know if it is possible in a neater way!

The reason for doing this is the overhaul of an existing site where indexes don't all start at 1 but they are used to link items in different tables

like image 845
MattP Avatar asked Dec 09 '22 10:12

MattP


1 Answers

Yes, the auto increment start position can be changed by altering the table.

ALTER TABLE t AUTO_INCREMENT = ?;
like image 186
a'r Avatar answered Dec 21 '22 16:12

a'r