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

后端 未结 4 1163
猫巷女王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:35

    This is By DesignTM, as you can see on Connect by the SQL Server team's response to a similar question:

    Thank you for your feedback. By design, the XACT_ABORT set option does not impact the behavior of the RAISERROR statement. We will consider your feedback to modify this behavior for a future release of SQL Server.

    Yes, this is a bit of an issue for some who hoped RAISERROR with a high severity (like 16) would be the same as an SQL execution error - it's not.

    Your workaround is just about what you need to do, and using an explicit transaction doesn't have any effect on the behavior you want to change.

提交回复
热议问题