使用从另一个表中选择的 MySQL 触发器更新

2022-01-01 00:00:00 mysql triggers

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

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.

相关文章