萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> 在SQL Server的try...catch語句中獲取錯誤消息代碼的的語句

在SQL Server的try...catch語句中獲取錯誤消息代碼的的語句

本文為大家詳細介紹下如何在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;

copyright © 萬盛學電腦網 all rights reserved