事务模板

create proc sp_Test
as
begin
begin transaction
begin try 

--sql语句省略

end try
begin catch
if(@@TRANCOUNT >0)
insert into tb_error (Message)values(ERROR_MESSAGE())--这句永远不会执行 有谁知道请留意
rollback transaction
end catch
if(@@TRANCOUNT >0)
commit transaction

原文地址:https://www.cnblogs.com/zhang9418hn/p/2293641.html