RAISERROR(不会中断事务)

来源:互联网 发布:算法图解 pdf 编辑:程序博客网 时间:2024/05/21 10:26

简单的传递信息可以使用级别0~9 。


如果你有sysadmin的角色,可以使用WITH LOG选项并设置一个严重级别>20的错误。error 发生的时候SQL Server会中断连接。


使用NOWAIT选项可以直接发送信息,而不用等大赛buffer


复制代码
RAISERROR ('Error in usp_InsertCategories stored procedure', 16, 0);


-- Formatting the RAISERROR string
RAISERROR ('Error in % stored procedure', 16, 0, N'usp_InsertCategories');


-- In addition, you can use a variable: 
GO
DECLARE @message AS NVARCHAR(1000) = N'Error in % stored procedure';
RAISERROR (@message, 16, 0, N'usp_InsertCategories');


-- And you can add the formatting outside RAISERROR using the FORMATMESSAGE function:
GO
DECLARE @message AS NVARCHAR(1000) = N'Error in % stored procedure';
SELECT @message = FORMATMESSAGE (@message, N'usp_InsertCategories');
RAISERROR (@message, 16, 0);
复制代码

0 0
原创粉丝点击