Nested transactions in Sql Server

后端 未结 4 1055
情话喂你
情话喂你 2020-12-04 19:49

Imagine the following scenario:

I am using SQL Server 2005. I have a transaction that is calling, among other SQL statements, a stored procedure that also has a tran

4条回答
  •  悲&欢浪女
    2020-12-04 20:16

    Yes the stored procedure will be rolled back.

    Here is the overall flow of your code:

    BEGIN TRY
    
        BEGIN TRANSACTION
    
        EXEC SotredProcedureName
    
        --Do some other activity
    
        COMMIT TRANSACTION
    END TRY
    BEGIN CATCH
    
        --IF an error occurs then rollback the current transaction, which includes the stored procedure code.
        ROLLBACK TRANSACTION
    
    END CATCH
    

    Cheers, John

提交回复
热议问题