How to ROLLBACK a transaction when testing using tSQLt

前端 未结 4 1448
离开以前
离开以前 2021-01-12 15:05

I recently was calling a procedure that contained a rasierror in the code. The raiserror was in a try catch block. Also a BEGIN TRAN was in the same try catch block after

4条回答
  •  太阳男子
    2021-01-12 15:29

    Better to use a BEGIN TRY block after BEGIN TRANSACTION. I did this when I had a similar problem. This is more logical, because in CATCH block I checked IF @@TRANCOUNT > 0 ROLLBACK. This condition doesn't need to be checked if another error is raised before BEGIN TRANSACTION. And in this case you can test your RAISERROR functionality.

提交回复
热议问题