CREATE PROCEDURE reset_xyz_autoincrement
BEGIN
SELECT @max := MAX(ID)+ 1 FROM ABC;
PREPARE stmt FROM 'ALTER TABLE XYZ AUTO_INCREMENT = ?'
EXECUTE stmt USING @max
DEALLOCATE PREPARE stmt;
END $$
我从这里获取代码: 如何使用另一个表中的 MAX 值重置 MySQL AutoIncrement?
这是 MySQL 输出:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN
SELECT @max := MAX(ID)+ 1 FROM ABC' at line 2