【问题标题】:mysql change the column id to start from 1 and auto increment from theremysql将列ID更改为从1开始并从那里自动递增
【发布时间】:2011-12-29 08:27:22
【问题描述】:

我在 phpmyadmin 中查看我的表,发现 id 从 13410 开始并增加 1。我想重置并从 1 开始。我读过很多人说最好不要管它,否则如果你弄乱了它会变得复杂,但我仍然需要一个解决方案,至少从 1 开始 id。 谢谢

【问题讨论】:

    标签: mysql auto-increment


    【解决方案1】:
    update *tablename* set id=id-13409;
    

    然后找到最高的id:select id from tablename order by id desc limit 1;

    然后重置auto_increment:alter table tablename auto_increment=12345;(将12345改为最高ID加一)

    【讨论】:

    • 你能说得更具体些吗?表名是 'author' 列名是 'id' 最低 id 是 13410 最后一个 id 是 26800,当然之后自动递增。谢谢!
    • 我做了第一行,它去了 1(它工作),想知道我是否还需要做你提到的以下两行?类型是 ID(11),extra 目前是 auto_increment,不确定我是否仍然执行以下两行代码。
    【解决方案2】:
    You can reset the auto increment to desired value using the following statement , 
    eg : mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;
    

    【讨论】:

      【解决方案3】:
      ALTER TABLE table AUTO_INCREMENT = 1
      

      http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

      我希望你知道自己在做什么!

      【讨论】:

      • 你和 AKhil 给出了一个非常简单的答案,我很喜欢,但我想知道它会影响数据还是让这件事变得复杂?出于某种原因,我觉得编写 Kae 提供的代码更安全。您对此有何建议或意见?
      猜你喜欢
      • 1970-01-01
      • 2017-11-03
      • 2011-12-29
      • 2012-05-31
      • 2013-10-27
      • 2011-06-09
      • 1970-01-01
      • 2017-02-19
      • 2014-10-01
      相关资源
      最近更新 更多