问题

如何重置字段的自动增量?我想让它再次从1开始计数.



解决方法

您可以使用以下重置计数器:

ALTER TABLE tablename AUTO_INCREMENT = 1

对于InnoDB,您不能将 auto_increment 值设置为低于或等于最高当前索引. (引自 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.

请参阅如何使用另一个表格中的MAX值重置MySQL自动填充? on如何动态获取可接受的值.




相关问题推荐