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 $$
ここからコードを取得しました: How to Reset an MySQL AutoIncrement using a MAX value from another table?
これは 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