所以我有一个更新后触发器,如果字段更改它将更新另一个表中列的数据,但是,事实证明它将更新所有行的整个列。
此触发器位于' order'表:
IF (NEW.status != OLD.status) THEN
UPDATE orderep SET status = (SELECT NEW.status FROM orders WHERE orders.orderNumber = OLD.orderNumber);
UPDATE order_audit SET status = (SELECT NEW.status FROM orders WHERE orderNumber = OLD.orderNumber);
END IF;
有什么想法吗?
答案 0 :(得分:3)
您在orderrep和order_audit表的UPDATE语句中缺少where子句,并且对订单的查找似乎是多余的。假设orderrep和order_audit引用了订单表:
IF (NEW.status != OLD.status) THEN
UPDATE orderep SET status = NEW.status WHERE orderrep.order_id = NEW.id ;
UPDATE order_audit SET status = NEW.status WHERE order_audit.order_id = NEW.id ;
END IF