自动增量不变 [英] Auto increment does not change

查看:46
本文介绍了自动增量不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改自动增量值以使其从特定数字开始:

I'm trying to change the auto increment value to make it starts from a specific number:

ALTER TABLE batchinfo AUTO_INCREMENT = 20000;

但是当我查询记录时,旧编号(1,2...)仍然存在,尽管该语句似乎成功了.我正在使用 MySQL 工作台.可能是什么问题?

But when I query the records, the old numbering (1,2...) still exists, although, the statement seems successful. I'm using MySQL workbench. What could be the problem ?

推荐答案

Altering AUTO_INCREMENT 不会改变过去的生成值,它只设置下一个生成的值.如果要更改过去的值,则需要执行 UPDATE.例如,像这样:

Altering AUTO_INCREMENT does not change past generated values, it only sets what the next generated value will be. If you want to change past values then you will need to perform an UPDATE. For example, something like this:

UPDATE batchinfo SET id = id + 19999;

注意不要有任何其他表引用此列,否则它们的引用将无效.(除非正确注明这些引用;只有 InnoDB 表支持外键.所有这些外键都必须使用 ON UPDATE CASCADE 定义,才能使该命令达到预期效果.)

Be careful that you don't have any other tables referencing this column, or their references will be invalidated. (Unless those references are properly noted; only InnoDB tables support foreign keys. And all of those foreign keys will have to be defined with ON UPDATE CASCADE for this command to have the intended effect.)

这篇关于自动增量不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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