如何使用另一个表中的MAX值重置MySQL自动增量? [英] How to Reset an MySQL AutoIncrement using a MAX value from another table?
本文介绍了如何使用另一个表中的MAX值重置MySQL自动增量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这行不通,以各种形式尝试过并且一直失败.实现以下结果的最简单方法是什么?
I know this won't work, tried it in various forms and failed all times. What is the simplest way to achieve the following result?
ALTER TABLE XYZ AUTO_INCREMENT = (select max(ID) from ABC);
这对于自动化项目非常有用.谢谢!
This is great for automation projects. Thank you!
SELECT @max := (max(ID)+1) from ABC; -> This works!
select ID from ABC where ID = (@max-1); -> This works!
ALTER TABLE XYZ AUTO_INCREMENT = (@max+1); -> This fails :( Why?
推荐答案
使用 查看全文