MySQL CREATE TRIGGER,语法错误。我做错了什么?

时间:2011-02-09 18:30:07

标签: mysql stored-procedures triggers concat

 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 ;

它会返回错误:

#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 

这是我第一次使用触发器,我正尽力寻找灵魂,但我失败了;<

1 个答案:

答案 0 :(得分:1)

您需要在此行中添加单词SET

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

此外,正如评论者指出的那样,OLD触发器中没有BEFORE INSERT值。