Db2在触发和写入日志之前

时间:2014-02-05 13:42:17

标签: sql logging triggers db2

我们有一个简单的触发器可以阻止插入:

db2 "CREATE TRIGGER noins_isrt
NO CASCADE BEFORE UPDATE ON userid.customer
REFERENCING NEW AS n
FOR EACH ROW MODE DB2SQL
SIGNAL SQLSTATE '99999' ('Updates not allowed')
"

有没有办法记录更新内容?例如,他们正在更新customer.name或电话号码?

1 个答案:

答案 0 :(得分:0)

我不知道DB2触发器的确切语法,但这是典型的语法:

CREATE TRIGGER noins_isrt
NO CASCADE BEFORE UPDATE ON userid.customer
REFERENCING NEW AS n
FOR EACH ROW MODE DB2SQL
begin
    insert into MyAuditTable(value)
        select new.value;
    SIGNAL SQLSTATE '99999' ('Updates not allowed')
end;