2

English is not my native language so forgive me if something in my question is not clear, I'll try to clarify.

I have to make a change in MySQL and I'm a little bit anxious about the result since the change will be made live. I have a table that have id's from 1-800 then there is a big jump to 10000, 10001, etc. I read in multiple questions like this one that you can use

ALTER TABLE tablename AUTO_INCREMENT = 1

My questions are :

  1. Will this reorder the current keys?
  2. What happen when my id get back up to 10000, will the ids be overwritten? (The collumn is primary)

In the case that it does reorder my keys or that they get overwritten (I can't have that happen), what would be the best solution to keep my table intact but have the id's be reset to 801? I absolutly need to keep the result untouch!!!

Thank you for taking the time to read/answer. Cheers.

4

2 回答 2

1

MySQL 不允许您将自动增量设置为低于当前最大键值的值。因此,您的应用程序必须手动设置 id 值。

于 2013-09-30T14:06:16.987 回答
0

使用此查询,将 tablename 和 id 更改为适当的表名和列名:

更新表名集 id = id - 9199 其中 id >= 10000

然后将您的自动增量设置为适当的下一个值。

您可能希望在更改之前保留表的备份副本。

于 2013-09-30T13:38:09.167 回答