开发者

MySQL: Can you specify the starting index?

开发者 https://www.devze.com 2023-02-18 13:52 出处:网络
Is it possible in MySQL to set the starting value of a primary key index, so it starts at say 15 instead of 1?

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 interest开发者_运维问答ed 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


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

ALTER TABLE t AUTO_INCREMENT = ?;


you can place auto increment value directly in SELECT statement - just place required 15 and next record would start as 16, 17, ...

0

精彩评论

暂无评论...
验证码 换一张
取 消