在MySQL触发器AFTER Update语句中获取旧值 [英] Get OLD Value in MySQL Trigger AFTER Update Statement
本文介绍了在MySQL触发器AFTER Update语句中获取旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下MySQL触发器
I have the following MySQL Trigger
SET @iUserId = OLD.LastChangedBy;
IF NOT NEW.LastChangedBy <=> OLD.LastChangedBy THEN
SET @iUserId = NEW.LastChangedBy;
END IF;
IF NOT NEW.BookingId<=> OLD.BookingId THEN
INSERT INTO AuditTrail VALUES (UUID(),@iUserId,'UPDATE','Booking', OLD.BookingId,'BookingType ',OLD.BookingType ,NEW.BookingType ,NOW());
END IF;
这称为CREATE TRIGGER Booking_AUPD
每行预订后更新
This is called as CREATE TRIGGER Booking_AUPD
AFTER UPDATE ON Booking FOR EACH ROW
我遇到的问题是如何在AFTER UPDATE触发器中获取OLD字段值?
The problem I have is how can I get the OLD field value in a AFTER UPDATE trigger ?
推荐答案
关于错误的最可能解释
"There is no OLD row in on INSERT trigger"
是您正在执行创建AFTER INSERT
触发器而不是创建AFTER UPDATE
触发器的语句.
is that you are executing a statement that's creating an AFTER INSERT
trigger, rather than creating an AFTER UPDATE
trigger.
由于该行位于INSERT之前,所以无法从该行引用OLD值,原因是该行在INSERT之前不存在.
The reason that you can't reference OLD values from the row, as the row existed prior to the INSERT, is that the row did not exist prior to the INSERT.
这篇关于在MySQL触发器AFTER Update语句中获取旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文