更改MySQL中Auto Increment值的当前计数? [英] Changing the current count of an Auto Increment value in MySQL?

查看:243
本文介绍了更改MySQL中Auto Increment值的当前计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,每次我向数据库中添加一个条目时,自动递增值都会按1递增.但是,它只有47个.因此,如果我添加一个新条目,它将是48个,然后另一个是49个,等等.

Currently every time I add an entry to my database, the auto increment value increments by 1, as it should. However, it is only at a count of 47. So, if I add a new entry, it will be 48, and then another it will be 49 etc.

我想更改当前自动增量"计数器的位置. IE.我想将其从47更改为10000,这样输入的下一个值将是10001.我该怎么做?

I want to change what the current Auto Increment counter is at. I.e. I want to change it from 47 to say, 10000, so that the next value entered, will be 10001. How do I do that?

推荐答案

您可以使用 ALTER TABLE 设置AUTO_INCREMENT列的值;引用该页面:

You can use ALTER TABLE to set the value of an AUTO_INCREMENT column ; quoting that page :

要更改 AUTO_INCREMENT计数器用于 新行,请执行以下操作:

To change the value of the AUTO_INCREMENT counter to be used for new rows, do this:

ALTER TABLE t2 AUTO_INCREMENT = value;

还有一个注释说:

您无法将计数器重置为 值小于或等于 已经被使用了.
对于MyISAM,如果 该值小于或等于 当前的最大值 AUTO_INCREMENT列,值为 重置为当前的最大值加一.
对于InnoDB,如果值小于 当前最大值 列,没有错误发生,并且 当前序列值未更改.

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.

希望这会有所帮助!

这篇关于更改MySQL中Auto Increment值的当前计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆