phpMyAdmin - 自动递增 ID
关于 phpMyAdmin 和自动增量的快速问题。如果我添加一个产品并且它被分配了 id 1,那么我在添加另一个产品之前将其删除,即使我删除了 id 1,下一个产品也会被赋予 id 2。我希望这是有道理的。
这有关系吗?
Quick question regarding phpMyAdmin and autoincrementing. If I add a product and it is assigned id 1, then I delete it before adding another, the next one is given the id 2 even though I deleted id 1. I hope this makes sense.
Does this matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,这是正常的 (My)SQL 行为。
No, this is normal (My)SQL behaviour.
这不是它的工作方式。自动递增值存储在变量中,并且只对其加一,而不是检查最大的值并对其加一。这是正常行为,看起来很乱,但工作正常。
Its not the way it works. The auto increment value is stored in a variable, and it only adds one to that, instead of checking the largest one and adding one to that. Its the normal behavior, it looks messy but it works fine.
考虑以下示例:您有 1000 行,并删除了 ID=1 的行。您是否希望下一个条目的 ID 为 1001 ?或 1 ?
这按预期工作,但如果您绝对必须,您可以像设置 MySQL 中的任何其他列一样手动设置该值。
Consider the example where you had 1000 rows, and deleted the row ID=1. Would you expect the next entry to be given an ID of 1001 ? or 1 ?
This is working as intended, though if you absolutely must, you can manually set the value just as you would any other column in MySQL.