0

我有一个巨大的批量插入导致错误:

DECLARE @row_terminator CHAR;
SET @row_terminator = CHAR(10); -- or char(10)

DECLARE @stmt NVARCHAR(2000);

SET @stmt = '
  BULK INSERT accn_billed_procedures
   FROM ''F:\2011-Dec\accn_billed_procedures_201112062112.txt.gz''
   WITH 
      (
        firstrow=2,
FIELDTERMINATOR = ''|''  ,
ROWS_PER_BATCH=10000
   ,ROWTERMINATOR='''+@row_terminator+'''
   )'
exec sp_executesql @stmt;
SET @stmt = '
  BULK INSERT accn_billed_procedures
   FROM ''F:\2011-Dec\accn_billed_procedures_201112072112.txt.gz''
   WITH 
      (
        firstrow=2,
FIELDTERMINATOR = ''|''  ,
ROWS_PER_BATCH=10000
   ,ROWTERMINATOR='''+@row_terminator+'''
   )'
exec sp_executesql @stmt;
SET @stmt = '
  BULK INSERT accn_billed_procedures
   FROM ''F:\2011-Dec\accn_billed_procedures_201112082112.txt.gz''
   WITH 
      (
        firstrow=2,
FIELDTERMINATOR = ''|''  ,
ROWS_PER_BATCH=10000
   ,ROWTERMINATOR='''+@row_terminator+'''
   )'
exec sp_executesql @stmt;
SET @stmt = '
  BULK INSERT accn_billed_procedures
   FROM ''F:\2011-Dec\accn_billed_procedures_201112092112.txt.gz''
   WITH 
      (
        firstrow=2,
FIELDTERMINATOR = ''|''  ,
ROWS_PER_BATCH=10000
   ,ROWTERMINATOR='''+@row_terminator+'''
   )'
exec sp_executesql @stmt;
SET @stmt = '
  BULK INSERT accn_billed_procedures
   FROM ''F:\2011-Dec\accn_billed_procedures_201112102112.txt.gz''
   WITH 
      (
        firstrow=2,
FIELDTERMINATOR = ''|''  ,
ROWS_PER_BATCH=10000
   ,ROWTERMINATOR='''+@row_terminator+'''
   )'
exec sp_executesql @stmt;

我想知道导致的所有错误(或至少很多错误)。

如果它需要我运行所有内容以获取错误列表,对我来说并不重要。

我只想知道是否可以显示 sql 语句将在 sql server 2008 中生成的所有错误?

4

2 回答 2

2

http://msdn.microsoft.com/en-us/library/ms175976.aspx

BEGIN TRY
    -- Table does not exist; object name resolution
    -- error not caught.
    SELECT * FROM NonexistentTable;
END TRY
BEGIN CATCH
    SELECT 
        ERROR_NUMBER() AS ErrorNumber
        ,ERROR_MESSAGE() AS ErrorMessage;
END CATCH
于 2012-05-08T01:33:05.553 回答
1

BULK INSERT有一个 ERRORFILE 参数。( http://msdn.microsoft.com/en-us/library/ms188365.aspx )

于 2012-07-19T22:25:10.363 回答