在使用上没什么区别,用Exec执行存储过程即可:--创建测试数据
create table t1(id int,status1 int)
insert into t1 select 1,0
insert into t1 select 2,0create table t2(id int,status2 int)
go--创建供触发器调用的存储过程
create procedure sp_test(@id int,@status1 int)
as
insert into t2 select @id,@status1
go--创建触发器
create trigger trg_t1 on t1
for update
as
begin
declare @id int,@status1 int
decare tc cursor for select id,status1 from deleted open tc fetch next from tc into @id,@status1 while @@fetch_status=0
begin
exec sp_test @id,@status1
fetch next from tc into @id,@status1
end close tc
deallocate tc
end
go--执行触发操作
update t1 set status1=1 where id=1--查看结果
select * from t2--清除测试环境
drop trigger trg_t1
drop function sp_test
drop table t1,t2
create table t1(id int,status1 int)
insert into t1 select 1,0
insert into t1 select 2,0create table t2(id int,status2 int)
go--创建供触发器调用的存储过程
create procedure sp_test(@id int,@status1 int)
as
insert into t2 select @id,@status1
go--创建触发器
create trigger trg_t1 on t1
for update
as
begin
declare @id int,@status1 int
decare tc cursor for select id,status1 from deleted open tc fetch next from tc into @id,@status1 while @@fetch_status=0
begin
exec sp_test @id,@status1
fetch next from tc into @id,@status1
end close tc
deallocate tc
end
go--执行触发操作
update t1 set status1=1 where id=1--查看结果
select * from t2--清除测试环境
drop trigger trg_t1
drop function sp_test
drop table t1,t2
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货