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

发布于 2024-10-16 19:23:59 字数 523 浏览 2 评论 0原文

 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 

这是我第一次使用触发器,我正在尽最大努力尝试找到灵魂,但我失败了;<

 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 ;

And it returns an error:

#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 

It's my first time with triggers and I was doing my best to try to find soultion but I failed ;<

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2024-10-23 19:24:00

您需要在这一行中添加单词 SET

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

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

You need to add the word SET in this line:

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

Also, as the commenter pointed out, there is no OLD value in a BEFORE INSERT trigger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文