在SQL Server的try...catch语句中获取错误消息代码的的语句
程序员文章站
2023-12-06 12:18:58
复制代码 代码如下: begin try ... ... end try begin catch declare @errormessage nvarchar(4000);...
复制代码 代码如下:
begin try
...
...
end try
begin catch
declare @errormessage nvarchar(4000);
declare @errorseverity int;
declare @errorstate int;
select
@errormessage = error_message(),
@errorseverity = error_severity(),
@errorstate = error_state();
raiserror (@errormessage, -- message text.
@errorseverity, -- severity.
@errorstate -- state.
);
end catch;