gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:58:23 25 4
gpt4 key购买 nike

 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

这是我第一次使用触发器,我尽我所能尝试寻找灵魂,但我失败了;<

最佳答案

你需要在这一行添加单词SET:

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

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

关于MySQL CREATE TRIGGER,语法错误。我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com