Home > Database > Mysql Tutorial > body text

在SQL Server的try...catch语句中获取错误消息代码的的语句

WBOY
Release: 2016-06-07 16:16:57
Original
1481 people have browsed it

本文为大家详细介绍下如何在SQL Server的try...catch语句中获取错误消息的代码,具体示例如下,感兴趣的朋友可以参考下哈,希望对大家有所帮助 复制代码 代码如下: BEGIN TRY ... ... END TRY BEGIN CATCH DECLARE @ErrorMessage NVARCHAR(4000); DECLARE @E

本文为大家详细介绍下如何在SQL Server的try...catch语句中获取错误消息的代码,,具体示例如下,感兴趣的朋友可以参考下哈,希望对大家有所帮助

 

复制代码 代码如下:


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;

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template