after和before区别:
一个是在记录操作之前触发,一个是在记录操作之后触发。
比如表之间定义的有外键,在删除主键时,必须要先删除外键表,这时就有先后之分。
语句级触发和行级触发区别:
语句级别触发器只触发一次、行级触发器是作用了多少行触发多少次。
如果定义为语句级,则Delete from t执行时,触发器只运行一次,
如果定义为行级,则上面的Delete操作将使触器运行多次(有几条记录就运行几次)。
上面是 最简单的区别,当然还有其他的区别
触发顺序上有所区别
语句级别触发器before
行级别触发器before
行级别触发器after
语句级别触发器after
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>create or replace trigger t1_triger_before
2 before insert on t1
3 begin
4 dbms_output.put_line('语句级别触发器before');
5 end;
6 /
Trigger created.
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>create or replace trigger t1_triger_after
2 after insert on t1
3 begin
4 dbms_output.put_line('语句级别触发器after');
5 end;
6 /
Trigger created.
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>create or replace trigger t1_triger_before_each_row
2 before insert on t1 for each row
3 begin
4 dbms_output.put_line('行级别触发器before');
5 end;
6 /
Trigger created.
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>create or replace trigger t1_triger_after_each_row
2 after insert on t1 for each row
3 begin
4 dbms_output.put_line('行级别触发器after');
5 end;
6 /
Trigger created.
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>set serveroutput on
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>--注意触发顺序
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>insert into t1 values(1,'a');
语句级别触发器before
行级别触发器before
行级别触发器after
语句级别触发器after
1 row created.
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>--注触发发次数
[TEST@ora10gr1#2009-12-18/21:08:09] SQL>insert into t1
2 select 1,'a' from dual union all
3 select 2,'b' from dual union all
4 select 3,'c' from dual;
语句级别触发器before
行级别触发器before
行级别触发器after
行级别触发器before
行级别触发器after
行级别触发器before
行级别触发器after
语句级别触发器after
3 rows created.