dongtiannai0654 2010-04-16 16:39
浏览 58
已采纳

使用Mysql脚本或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

  • 写回答

3条回答 默认 最新

  • douzhi0107 2010-04-16 16:41
    关注

    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?

    Since autoincrement fields are typically used as keys linking to other tables, renumbering existing records is not done often. If you REALLY want to renumber them all, copy the records to a new table but leave off the autoincrement field. TRUNCATE the original table and copy back the original records, supplying NULL for the autoincrement 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路