简体   繁体   English

更改AUTO_INCREMENT值

[英]Change AUTO_INCREMENT value

I'm using MySQL 5.6.12 . 我正在使用MySQL 5.6.12 I tried this command, but didn't work. 我尝试了此命令,但是没有用。

ALTER TABLE food AUTO_INCREMENT = 1;  
ALTER TABLE food AUTO_INCREMENT=1;

I tried with my winform application and by EMS MySQL manager , neither worked. 我尝试使用Winform应用程序和EMS MySQL管理器 ,但均无效果。
I Already tried some of the answers I found here, but nothing yet... 我已经尝试了一些在这里找到的答案,但是还没有...

No errors at all. 完全没有错误。 The query executes perfect, it just does not change the AUTO_INCREMENT value. 查询执行完美,只是不更改AUTO_INCREMENT值。

If you're trying to lower the auto increment value, it may not work as you expect. 如果您尝试降低自动增量值,则可能无法按预期工作。 From the MySQL Documentation : 从MySQL 文档

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,如果该值小于该列中的当前最大值,则不会发生错误,并且当前序列值不会更改。

Since you're trying to set it to 1 , this won't work unless the table is empty, since that's necessarily less than the current maximum value. 由于您尝试将其设置为1 ,除非表为空,否则该方法将不起作用,因为该值必须小于当前最大值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM