2011-02-09 53 views
1
DELIMITER || 
CREATE TRIGGER `monthly_insert` BEFORE INSERT ON `history_monthly` 
FOR EACH ROW 
BEGIN 
    NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`); 
END; 
|| 
DELIMITER ; 

並返回一個錯誤:MySQL CREATE TRIGGER,語法錯誤。我做錯了什麼?

#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 '.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`); 
END' at line 4 

這是我第一次用觸發器和我盡我所能,試圖找到soultion但我失敗了; <

+0

如果這是一個`BEFORE INSERT`觸發器,肯定不會有舊行? – 2011-02-09 18:37:23

回答

1

您需要添加這一行字SET

SET NEW.`uid` = CONCAT(OLD.`year`, OLD.`month`, OLD.`charactersId`); 

此外,作爲評論者指出的那樣,有一個BEFORE INSERT觸發沒有OLD值。