经由过程示例来讲明:
先创立一个存储历程usp_demo,该存储历程承受参数@aint与@bint,在存储过程当中盘算这两个参数的和并将了局拔出光临时表#table:
createprocedureusp_demo
@aint,
@bint
as
declare@cint
set@c=@a+@b
insertinto#table(ID)values(@c)
再创立一时表#table
createtable#table
(
IDint
)
然后我要将数据集
select1asa,2asb
union
select3asa,10asb
union
select4asa,12asb
拔出到表#table中
办法一:经由过程存储历程usp_demo将测试数据拔出到表#table中,处置办法应当是如许的。
declare@aint
declare@bint
declarere_cusorcursorforselect1asa,2asb
union
select3asa,10asb
union
select4asa,12asb
openre_cusor
fetchnextfromre_cusorinto@a,@b
while@@fetch_status=0
begin
execusp_demo@a,@b
fetchnextfromre_cusorinto@a,@b
end
然后为该表创立instead触发器
createtriggeriti_ut_demoonut_demoinsteadofinsert
as
insertinto#table(ID)
selecta+bfrominserted
如许,触发器iti_ut_demo即中止了对表ut_demo的操纵,又往#table中拔出了数据。我们将数据集
select1asa,2asb
union
select3asa,10asb
union
select4asa,12asb
拔出表#table中的办法为:
insertintout_demo(a,b)
select1asa,2asb
union
select3asa,10asb
union
select4asa,12asb