我有2个表路由和loc。当路由表中的drivername或rt_num发生变化时,我需要更新loc表。我整天都在尝试使用以下代码。每个UPDATE语句都由它自己作为触发器。我不确定它是否可以完成。
DELIMITER | CREATE TRIGGER `add2` AFTER UPDATE ON `route` FOR EACH ROW BEGIN AFTER UPDATE ON `route`; UPDATE loc SET drivername = new.driver_d_name WHERE rt_nanme = old.rt_num; UPDATE loc SET rt_nanme = new.rt_num WHERE rt_nanme = old.rt_num; END; | DELIMITER ;
答案 0 :(得分:0)
having multiple updates in a single trigger没有错。但是你的触发器有一个语法问题,这可能导致失败。试试这个:
/etc/php/5.6/apache2/php.ini
答案 1 :(得分:0)
将其与旧值进行比较
#requireResource
答案 2 :(得分:0)
为什么要重复after update
声明?
此外,您不需要两个更新语句。所以:
DELIMITER $$
CREATE TRIGGER `add2` AFTER UPDATE ON `route`
FOR EACH ROW
BEGIN
UPDATE loc
SET drivername = new.driver_d_name,
rt_nanme = new.rt_num
WHERE rt_nanme = old.rt_num;
END;$$
DELIMITER ;