如何获得SQL Server 2008R2向我展示错误?
-
30-09-2019 - |
题
我正在运行一个插入脚本,该脚本应该将13,381行插入SSM的空白db中。它告诉我我的“查询已经错误地完成”,并且仅插入13357行。
错误列表中什么都没有出现。如何在脚本中找到错误?
谢谢!
解决方案
尝试这个:
begin try
--your inserts here
end try
begin catch
--returns the complete original error message as a result set
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_SEVERITY() AS ErrorSeverity
,ERROR_STATE() AS ErrorState
,ERROR_PROCEDURE() AS ErrorProcedure
,ERROR_LINE() AS ErrorLine
,ERROR_MESSAGE() AS ErrorMessage
--will return the complete original error message as an error message
DECLARE @ErrorMessage nvarchar(400), @ErrorNumber int, @ErrorSeverity int, @ErrorState int, @ErrorLine int
SELECT @ErrorMessage = N'Error %d, Line %d, Message: '+ERROR_MESSAGE(),@ErrorNumber = ERROR_NUMBER(),@ErrorSeverity = ERROR_SEVERITY(),@ErrorState = ERROR_STATE(),@ErrorLine = ERROR_LINE()
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState, @ErrorNumber,@ErrorLine)
end catch
不隶属于 StackOverflow