Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

mysql - 如何在MySQL中重置AUTO_INCREMENT?(How to reset AUTO_INCREMENT in MySQL?)

How can I reset the AUTO_INCREMENT of a field?

(如何重置字段的AUTO_INCREMENT ?)

I want it to start counting from 1 again.

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

  ask by home rrrrrrrr translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

(对于InnoDB,您不能将auto_increment值设置为auto_increment或等于当前最大索引。)

(quote from ViralPatel ):

((引自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.

(对于MyISAM,如果该值小于或等于AUTO_INCREMENT列中当前的最大值,则该值将重置为当前的最大值加1。)

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.

(对于InnoDB,如果该值小于该列中的当前最大值,则不会发生错误,并且当前序列值不会更改。)

See How to Reset an MySQL AutoIncrement using a MAX value from another table?

(请参见如何使用另一个表中的MAX值重置MySQL自动增量?)

on how to dynamically get an acceptable value.

(如何动态获得可接受的值。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...