Why does Sql Server keep executing after raiserror when xact_abort is on?

后端 未结 4 1180
猫巷女王i
猫巷女王i 2020-12-23 16:01

I just got surprised by something in TSQL. I thought that if xact_abort was on, calling something like

raiserror(\'Something bad happened\', 16, 1);
         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 16:24

    As pointed out on the docs for SET XACT_ABORT, the THROW statement should be used instead of RAISERROR.

    The two behave slightly differently. But when XACT_ABORT is set to ON, then you should always use the THROW command.

提交回复
热议问题