使用从另一个表中选择的 MySQL 触发器更新 [英] MySQL Trigger Update with select from another table

查看:40
本文介绍了使用从另一个表中选择的 MySQL 触发器更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚了解触发器,我创建了以下触发器;

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?

推荐答案

实际上我自己已经设法解决了这个问题.这是更新后的代码

I've actually managed to solve this myself. Here is the updated code

CREATE TRIGGER `incremental_before_ins_tr` BEFORE INSERT ON `incremental`
FOR EACH ROW
BEGIN
SET NEW.source = (Select source from crm_record
where crm_record.msisdn = new.msisdn order by dat DESC limit 1);
END;

我需要在第 5 行的列值之前指定表名.

I needed to specify the table name prior to the column value on line 5.

这篇关于使用从另一个表中选择的 MySQL 触发器更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆