oracle 用触发器记录操作

create or replace trigger tri_dbset AFTER INSERT OR UPDATE OR DELETE
on t_sjzx_dbset for each row
begin
   IF INSERTING THEN
     insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:new.id,:new.name,:new.remark,:new.tablename,:new.classid,1);
   ELSIF UPDATING THEN
     insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:new.id,:new.name,:new.remark,:new.tablename,:new.classid,2);
   ELSIF DELETING THEN
     insert into t_tri_dbset(id,name,remark,tablename,classid,actfield) values(:old.id,:old.name,:old.remark,:old.tablename,:old.classid,3);
   END IF;
END;

几个关键:
1、AFTER INSERT OR UPDATE OR DELETE
2、for each row 行级,不加就是表级
3、:new 新记录
4、:old 旧记录

你可能感兴趣的:(数据库)