从另一个表中选择的MySQL触发器更新 [英] MySQL Trigger Update with select from another table
本文介绍了从另一个表中选择的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屋!
查看全文