2011-05-11 66 views

回答

1

你可以用整个事情在一个事务中,它会工作,但你必须确保所有的孩子/嵌套的存储过程将回滚事务,否则你会造成僵局。这样的事情:

 

Create procedure [dbo].[parent] 
as 
Begin Transaction 
Begin Try 
    Exec Child 
End Try 
Begin Catch 
    If @@Trancount > 0 
     RollBack 
End Catch 
Commit 


Create procedure [dbo].[Child] 
as 
Begin Transaction 
Begin Try 
    --Do inserts here 
End Try 
Begin Catch 
    If @@Trancount > 0 
     RollBack 
    RAISERROR('Error Occured',16,1) 
End Catch 
Commit 

 
+0

好的,得到,谢谢。 – sobsinha 2011-05-12 09:41:28