mssql sqlserver 触发器中调用存储过程的方法分享


摘要:
下文讲述sql脚本中触发器调用存储过程的方法分享,如下所示


create table testA
(keyId int identity,
info varchar(30))
go

create table testB
(keyId int identity,
info xml)
go

create proc pr_testB_insert
@info xml
as
begin
 insert into testB
 (info)values(@info)
end
go


create trigger tr_testA
 on testA
 for insert 
 as 
 begin 
    declare @a  xml 
    select @a = (select info from inserted for xml auto)
    
    ---触发器中调用存储过程的方法分享
    exec pr_testB_insert @a 
 end
 
 go
 
 ---数据实验
 insert into testA(info)values(N'sql教程blog');
 go
 ---数据检测
 select * from testA
 select * from testB
 
 go
 drop proc pr_testB_insert
 drop trigger tr_testA
 go
 
 truncate table testA
 drop     table testA
 
 truncate table testB
 drop     table testB