如何使用触发器把更新的表记录更新回来

来源:百度知道 编辑:UC知道 时间:2024/06/16 20:49:55
create or replace trigger trg_pty_empee
before update of EMPEE_PWD on crmshare.tb_pty_empee
for each row
when (old.empee_id in ('1','21','274250'))
declare
-- local variables here
begin
if (:new.EMPEE_PWD is null or :new.EMPEE_PWD <> :old.EMPEE_PWD) then
:new.EMPEE_PWD := :old.EMPEE_PWD;
end if;
end;

例如你有一个BigClass表跟一个PermanentAssets表,PermanentAssets表中的Psort列外建引用了BigClass表中的Bname列
如果BigClass列中的Bname值被更改,那么PermanentAssets表中的Psort列值也随之更改

create trigger tr_bigclass on bigclass for update
as
if(update(Bname))
update PermanentAssets set Psort=b.Bname from PermanentAssets a,inserted b,deleted c
where Psort=c.Bname

这是为什么呢?更新啦,还要更新回来,最简单的方法就是做个触发器在看到update语句的时候不做任何操作就可以啦,