gpt4 book ai didi

mysql - 如何在 MySQL 中重置 AUTO_INCREMENT

转载 作者:IT老高 更新时间:2023-10-28 12:47:17 32 4
gpt4 key购买 nike

我如何重置字段的AUTO_INCREMENT

我希望它再次从 1 开始计数。

最佳答案

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

ALTER TABLE tablename AUTO_INCREMENT = 1

对于 InnoDB您不能将 auto_increment 值设置为低于或等于当前最高索引。 (引自 ViralPatel ):

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

How can I reset an MySQL AutoIncrement using a MAX value from another table? 关于如何动态获取可接受的值。

关于mysql - 如何在 MySQL 中重置 AUTO_INCREMENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8923114/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com