18
我正在運行一個插入腳本,應該從SSMS插入13,381行到空白數據庫。它告訴我的「查詢完成,有錯誤」,只能插入13357行。如何獲取SQL Server 2008r2向我顯示錯誤?
錯誤列表中沒有顯示任何內容。我如何找到腳本中的錯誤?
謝謝!
我正在運行一個插入腳本,應該從SSMS插入13,381行到空白數據庫。它告訴我的「查詢完成,有錯誤」,只能插入13357行。如何獲取SQL Server 2008r2向我顯示錯誤?
錯誤列表中沒有顯示任何內容。我如何找到腳本中的錯誤?
謝謝!
試試這個:
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
SWEET是一個代碼方便一點謝謝! – 2010-12-03 16:57:46