ppluncle

我奋斗,我精彩!

导航

触发器---FOR INSERT与INSTEAD OF

注:
下面的实例由CSDN论坛MS-SQL server版块中internetcsdn (公元1979年8月10日) 网友提供
测试一.
--------------
create table tb1 (id int identity(1,1), a varchar(10))
create trigger tri_tb1 on tb1 INSTEAD OF  insert
as 
begin
 insert tb1 (a)
 select a from inserted 
end

insert tb1(a)
select 'a'

select * from tb1
/*
id             a
-----------------
1             a
*/

-------------------------------------------------------------------
-------------------------------------------------------------------

测试一.
--------------
create table tb1 (id int identity(1,1), a varchar(10))
create trigger tri_tb1 on tb1 for  insert
as 
begin
 insert tb1 (a)
 select a from inserted 
end

insert tb1(a)
select 'a'

select * from tb1
/*
id             a
-----------------
1             a
2             a
*/

==========================================================
结论:FOR INSERT,插入动作完成后执行触发语句.
       INDSTEAD OF INSERT,用触发语句来代替插入语句.

AFTER
指定触发器只有在触发 SQL 语句中指定的所有操作都已成功执行后才激发。所有的引用级联操作和约束检查也必须成功完成后,才能执行此触发器。
如果仅指定 FOR 关键字,则 AFTER 是默认设置。


INSTEAD OF
指定执行触发器而不是执行触发 SQL 语句,从而替代触发语句的操作

posted on 2004-06-24 15:32  .net学习中-人是逼出来的  阅读(704)  评论(0)    收藏  举报