Executing a stored procedure inside BEGIN/END TRANSACTION

前端 未结 7 1094
谎友^
谎友^ 2020-12-13 06:28

If I create a Stored Procedure in SQL and call it (EXEC spStoredProcedure) within the BEGIN/END TRANSACTION, does this other stored procedure also fall into the

7条回答
  •  误落风尘
    2020-12-13 06:44

    Sounds great, thanks a bunch. I ended up doing something like this (because I'm on 05)

        BEGIN TRY
           BEGIN TRANSACTION
    
           DO SOMETHING
    
           COMMIT
        END TRY
        BEGIN CATCH
          IF @@TRANCOUNT > 0
             ROLLBACK
    
          -- Raise an error with the details of the exception
          DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
          SELECT @ErrMsg = ERROR_MESSAGE(),
                 @ErrSeverity = ERROR_SEVERITY()
    
          RAISERROR(@ErrMsg, @ErrSeverity, 1)
        END CATCH
    

提交回复
热议问题