Get OLD Value in MySQL Trigger AFTER Update Statement(在更新语句后获取 MySQL 触发器中的旧值)
问题描述
我有以下 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
AFTER ON Booking FOR EACH ROW
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.
不能从行中引用 OLD 值的原因是该行在 INSERT 之前存在,是因为该行在 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 触发器中的旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在更新语句后获取 MySQL 触发器中的旧值


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01