帮我写个存储过程的错误调试 当外部事务调用 存储的时候 判断 如果是 外部事务出错 则 回滚到存储过程中的保存点
并且判断 是外部事务出错 事务是否可提交 或着是 毁灭 或者 没事务
如果是 存储里面出错 比如 约束违规 则 
并且判断 是内部事务出错 事务是否可提交 或着是 毁灭 或者 没事务help mealter proc testing
as
declare @tcount int 
select @tcount=@@trancount
if @tcount>0
save tran s1
if @tcount=0
begin
 begin try
   begin tran
   insert into # select 1 
   if xact_state()=0
   begin
    commit tran
   end
 end try
 begin catch
  if @tcount=0
  begin
   if xact_state()=0 print 'no tran open'
   if xact_state()=1 
   begin
   rollback tran
   print 'tran can committed ,pro is error and  rollback'
   end
   if xact_state()=-1
   begin
   commit tran  
   print 'tran can uncommitted, pro is error and commit'
   end
  end
 if @tcount>0
 begin
  if xact_state()=0 
  print 'no tran open and pro outside is error'
  if xact_state()=1 
  begin 
    rollback tran s1
    print 'tran roll back s1 and  pro outside is error'
  end
  if xact_state()=-1
  begin
   commit tran 
   print 'tran can uncommitted, pro outside error and commit'
  end
 end
end catch
end
go总觉得有问题又说不出在哪里 理解不够 期待解惑者