perhaps? 2012-01-19 08:37 采纳率: 100%
浏览 535
已采纳

如何在 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

  • 写回答

21条回答 默认 最新

  • elliott.david 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.

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

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持