我知道这是行不通的,以各种形式尝试过并且一直失败。实现以下结果的最简单方法是什么?
ALTER TABLE XYZ AUTO_INCREMENT = (select max(ID) from ABC);
这对于自动化项目非常有用。谢谢!
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?
使用准备好的语句:
SELECT @max := MAX(ID)+ 1 FROM ABC; PREPARE stmt FROM 'ALTER TABLE ABC AUTO_INCREMENT = ?'; EXECUTE stmt USING @max; DEALLOCATE PREPARE stmt;