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不接受這個程序。你能幫忙嗎?
這是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
我甚至在發佈之前,但仍然沒有運氣嘗試過。我得到並再次出現錯誤: '#1064 - 您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在'BEGIN SELECT @max:= MAX(id)+ 1 FROM movies'附近使用正確的語法;在第2行準備好'ALTER TABL' 我也試過用'delimiter;'也沒有運氣... –