触发器写法:
create or replace trigger testTrigger
before insert or update or delete
on t_yunwei_group
for each row
declare
-- local variables here
begin
if inserting then
insert into t_yunwei_stalocation t1 (t1.c_groupid,t1.c_groupName,t1.c_filecontent) values (:NEW.c_Groupid,:NEW.c_groupname,' ');
end if;
if updating then
update t_yunwei_stalocation t1 set t1.c_groupname=:NEW.c_groupname where t1.c_groupid=:NEW.c_Groupid;
end if;
if deleting then
delete from t_yunwei_stalocation t1 where t1.c_groupid=:OLD.c_Groupid;
end if;
end testTrigger;
注: :old 与:new 的区别:
顾名思义,new是新插入的数据,old是原来的数据
insert只会有new,代表着要插入的新记录
delete只会有old,代表着要删除的记录
update由于执行的是先删除旧的记录,再插入新的记录,因此new和old都会有,且含义与上面的相同
注:update触发器,可根据具体需求选择记录旧记录还是新记录。