derek5. 2012-01-19 08:37 采纳率: 100%
浏览 484
已采纳

如何在 MySQL 中重置自动增量?

How can I reset the AUTO_INCREMENT of a field? I want it to start counting from 1 again.

转载于:https://stackoverflow.com/questions/8923114/how-to-reset-auto-increment-in-mysql

  • 写回答

19条回答 默认 最新

  • 七度&光 2012-01-19 08:39
    关注

    You can reset the counter with:

    ALTER TABLE tablename AUTO_INCREMENT = 1
    

    For InnoDB you cannot set the auto_increment value lower or equal to the highest current index. (quote from ViralPatel):

    Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

    See How to Reset an MySQL AutoIncrement using a MAX value from another table? on how to dynamically get an acceptable value.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?