测试一.
--------------
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
endinsert 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
endinsert tb1(a)
select 'a'select * from tb1
/*
id a
-----------------
1 a
2 a
*/==========================================================
结论:FOR INSERT,插入动作完成后执行触发语句.
INDSTEAD OF INSERT,用触发语句来代替插入语句.这样理触对不对啊?
--------------
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
endinsert 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
endinsert tb1(a)
select 'a'select * from tb1
/*
id a
-----------------
1 a
2 a
*/==========================================================
结论:FOR INSERT,插入动作完成后执行触发语句.
INDSTEAD OF INSERT,用触发语句来代替插入语句.这样理触对不对啊?
指定触发器只有在触发 SQL 语句中指定的所有操作都已成功执行后才激发。所有的引用级联操作和约束检查也必须成功完成后,才能执行此触发器。
如果仅指定 FOR 关键字,则 AFTER 是默认设置。
INSTEAD OF
指定执行触发器而不是执行触发 SQL 语句,从而替代触发语句的操作。
所以你的理解是对的