LoginSignup
7
4

More than 5 years have passed since last update.

sql serverでbulk insertに失敗した際に、行を特定する書き方

Posted at

以下のように書くと、エラー内容だけでなく、エラーを起こした行がキャッチできるので、内容を特定しやすい

BEGIN TRY
BULK INSERT テーブル名 FROM 'ファイルパス'
WITH (ファイル構造情報)
END TRY
BEGIN CATCH
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;
END CATCH
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4