在SQL Server的try...catch语句中获取错误消息代码的的语句
程序员文章站
2023-11-16 21:24:28
复制代码 代码如下: 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;
上一篇: SQL分组排序去重复的小实例