使用 Mysql 脚本或 PHP 重新生成 MySQL 表中的 ID 行
我有一个数据库,其中包含使用我的网页的用户的信息。许多MySql表都有ID参数,该表是自增的。问题是,当有人从网站上删除他的帐户时,数据库中仍然存在我不希望的序列跳转,因为我有一个脚本,如果在 ID 中找到一些跳转,该脚本就会失败。
前任。
ID Name PASS
1 Jhon 1234
2 Max 2233
3 Jorge 2232
如果 Max 退出并有新用户进入,就会发生这种情况。
ID Name PASS
1 Jhon 1234
4 NewU 1133
3 Jorge 2232
那么,为了避免这种问题,从数据库中删除某些内容的最佳方法是什么,或者如果没有办法,可以使用 PHP 或 MySql 脚本来删除 ID 行中的所有内容并在中重新生成它命令?多谢!对不起我的英语
i have a database fill with information of the users who use my webpage. The table as many MySql tables have the ID parameters who is autoincrement. The issue is that when somebody eliminate his account from the site, in the database remain a jump in the sequence that i dont want cuz i have a script who fail if find some jump in the ID.
Ex.
ID Name PASS
1 Jhon 1234
2 Max 2233
3 Jorge 2232
If Max get out and a new user go in, this is what will happend.
ID Name PASS
1 Jhon 1234
4 NewU 1133
3 Jorge 2232
So what is the best way to erase some body from the data base in order to avoid this isuue, or if is not a way, its posible to do a PHP or MySql script who eliminate all the contents in the ID row and regenerate it in order? Thanks A lot! sorry for my english
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为不是自动增量的问题,而是你的脚本的问题。
几乎从不您想要重组数据库中的自动增量数字。这违背了目的。
我宁愿建议您修复脚本。
这是各种错误,但来自 重置自动增量字段?
使用这种方法,您还必须手动更新所有外键、指向这些新 ID 的链接,与修复脚本相比,这似乎是一项非常大的任务
I think not the issue with AUTOINCREMENT, but rather your script.
ALMOST NEVER do you want to restructure autoincrement numbers in a database. That defeats the purpose.
I would rather recomend you work on fixing your script.
This is all kinds of wrong, but from Reset a auto increment field?
Using this approach, you will also have to manually update all foreign keys, links to these new IDs, which seems like a very big taks compared to fixing your script
不建议您尝试保持主键顺序。最好重写脚本以消除这种依赖性。更改数据的主键对于数据完整性和性能来说都是一个坏主意。
It is not recommended that you try to keep your primary keys sequential. It is much better to rewrite your script to not have this dependency. Changing primary keys on your data is a bad idea for both data integrity and performance.
不建议重新排列表中的主键。正如您所拥有的表是用户表。它可能通过外键与另一个表相关。用户表的主键可能在另一个表中被引用。如果您重新排列表中的主键,您还必须管理所有相关表。
因此,请尝试修复脚本中的错误。
It is not recommended to re-arrange the primary keys in a table. As you have the table is users table. It may be related to another tables by foreign key. There may be reference of user table's primary key in another table. In case you re-arrange primary key in the table you also have to manage all related tables also.
So try to fix the bugs in your script.