以编程方式设置AUTO_INCREMENT值 [英] Set AUTO_INCREMENT value programmatically

查看:77
本文介绍了以编程方式设置AUTO_INCREMENT值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这行得通...

ALTER TABLE variation AUTO_INCREMENT = 10;

但是我想这样做;

ALTER TABLE variation AUTO_INCREMENT = (SELECT MAX(id)+1 FROM old_db.varaition);

但是那行不通,也不行;

but that doesnt work, and neither does;

SELECT MAX(id)+1 INTO @old_auto_inc FROM old_db.variation 
ALTER TABLE variation AUTO_INCREMENT = @old_auto_inc;

那么有谁知道该怎么做?

So does anyone know how to do this?

(我正在尝试确保AUTO_INCREMENT密钥不会在新旧站点之间发生冲突,并且需要自动执行此操作.因此,我可以在新数据库上线时运行脚本)

( I'm trying to ensure that AUTO_INCREMENT keys dont collide between an old and a new site and need to do this automatically. So I can just run a script when the new db goes live )

推荐答案

将您的auto_increment设置为1,零不起作用,mysql自动将最大值设置为索引值的下一个值.

Set your auto_increment in 1, zero doesn't work, automatically mysql set the maximum value to the next value for index value.

ALTER TABLE table AUTO_INCREMENT = 1

这篇关于以编程方式设置AUTO_INCREMENT值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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