MySQL 触发器更新并从另一个表中选择
只是学习触发器,我创建了以下触发器;
CREATE TRIGGER `incremental_before_ins_tr` BEFORE INSERT ON incremental`
FOR EACH ROW
BEGIN
SET NEW.source = (Select source from crm_record
where msisdn = new.msisdn order by dat DESC limit 1);
END;
然而,该值似乎没有得到更新。有什么想法吗?
Just learning about triggers and I'm created the following trigger;
CREATE TRIGGER `incremental_before_ins_tr` BEFORE INSERT ON incremental`
FOR EACH ROW
BEGIN
SET NEW.source = (Select source from crm_record
where msisdn = new.msisdn order by dat DESC limit 1);
END;
However the value does not appear to be getting updated. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我实际上已经自己解决了这个问题。 更新代码。
下面是我需要在第 5 行的列值之前指定表名称的
I've actually managed to solve this myself. Here is the updated code
I needed to specify the table name prior to the column value on line 5.
看来您有一个错字。
您输入的增量带有尾随反引号,而不是用反引号括起来。
您的触发器现在可能绑定到一个名为
incremental`
的表,我假设该表不存在。既然你已经排除了上述情况。我发现缺少 UPDATE 关键字。在 SET 行之前添加
UPDATE table
。将 table 替换为您的表的名称。Looks like you have a typo.
You have entered incremental with a trailing backtick instead of enclosing it in backticks.
It is likely that your trigger is now bound to a table called
incremental`
which I am assuming does not exist.Since you have ruled out the above. I see that the UPDATE keyword is missing. Add
UPDATE table
before your SET line. Replace table with the name of your table.