MySQL:忘记设置自动增量
我设置了一个数据库,其中有一个自动递增列,该列本来就是一个 ID。问题是我在 phpMyAdmin 中创建表时忘记检查自动增量...直到现在才注意到!所以我所拥有的是这样的:
ID | column one | column two
------------------------------------
0 | some value | some value
0 | other value | something else
0 | example val. | something
0 | my example | something
基本上,我的“自动递增”列全面显示零。我如何修改此表以显示所有先前和所有未来行的自动增量?
I set up a database, with an auto incrementing column that was meant to be an ID. The problem is that I forgot to check off auto increment when creating the table in phpMyAdmin...and didn't notice until now! So what I have is something like:
ID | column one | column two
------------------------------------
0 | some value | some value
0 | other value | something else
0 | example val. | something
0 | my example | something
Basically, my "auto incrementing" column shows zeros across the board. How could I modify this table to show auto increment for all previous and all future rows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果表是空的,你可以这样做:
但我不确定其中的行会发生什么。最好创建一个具有正确定义的新表,将数据复制到减去 id 列的位置,删除旧的(错误的)表,然后将新表移至旧名称。
我确信 phpMyAdmin 能够以更图形化的方式完成此操作。
If the table were empty you could just do:
but I'm not sure what will happen with rows in it. It might be best to create a new one with the correct definitions, copy the data over minus the id column, drop the old (wrong) table, and move the new one to the old name.
I'm sure phpMyAdmin has the ability to do this more graphically.
首先更新您的记录(否则您将得到重复的主键):
然后添加主键/自动增量:
然后设置下一个自动增量:
First update your records (otherwise you will get duplicate primary key):
Then add the primary key/auto_increment:
Then set the next auto_increment:
您可以删除 ID 列并重新创建它。如果您记得启用自动增量,则会重新分配 id;)
You could drop the ID column and re-create it. The ids will be reassigned, if you remembered to enable the auto increment ;)