同时插入2条数据时,触发器执行一次,intserted有2条数据.create table #ins(aid int,col varchar(5))create table 表a
(aid int,col varchar(5))create trigger 触发器b on 表a
for insert
as
begin
insert into #ins(aid,col)
select aid,col from inserted
end-- 同时插入2条数据
insert into 表a(aid,col)
select 11,'aa' union all
select 22,'bb'
/*
(2 row(s) affected) --> 针对表a的2条记录(2 row(s) affected) --> 针对#ins的2条记录
*/-- 结果
select aid,col from 表a
/*
aid col
----------- -----
11 aa
22 bb(2 row(s) affected)
*/select aid,col from #ins/*
aid col
----------- -----
22 bb
11 aa(2 row(s) affected)
*/
(aid int,col varchar(5))create trigger 触发器b on 表a
for insert
as
begin
insert into #ins(aid,col)
select aid,col from inserted
end-- 同时插入2条数据
insert into 表a(aid,col)
select 11,'aa' union all
select 22,'bb'
/*
(2 row(s) affected) --> 针对表a的2条记录(2 row(s) affected) --> 针对#ins的2条记录
*/-- 结果
select aid,col from 表a
/*
aid col
----------- -----
11 aa
22 bb(2 row(s) affected)
*/select aid,col from #ins/*
aid col
----------- -----
22 bb
11 aa(2 row(s) affected)
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货