我想在firebird db上创建一个触发器:
SET TERM ^ ;
create trigger log_trigger_error for test
before insert or update
as
begin
INSERT INTO test_log (a,b)
select case when (new.rdb$field_name is null and old.rdb$field_name is not null
or new.rdb$field_name is not null and old.rdb$field_name is null
or new.rdb$field_name <> old.rdb$field_name)
then new.rdb$field_name
else old.rdb$field_name as a
end , 2 as b
from rdb$relation_fields
where rdb$relation_name ='TEST';
end^
SET TERM ; ^
答案 0 :(得分:2)
您正在为表test
创建触发器,但随后在触发器正文中,您在表new
中选择了old
和rdb$relation_fields
个上下文变量。这是不可能的,new
和old
变量仅适用于触发器所用的表。
如果要记录对数据的更改,请使用
之类的触发器create trigger log_trigger_error for test before update
as
begin
INSERT INTO test_log (a, b) VALUES(old.a, old.b);
end^
现在,当更新test
表中的记录时,旧值将记录到test_log
表中。