如何使用另一个表中的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?

使用 查看更多