Determine ROW that caused “unexpected end of file” error in BULK INSERT?

后端 未结 11 1987
闹比i
闹比i 2020-12-16 10:18

i am doing a bulk insert:

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

DECLARE @stmt NVARCHAR(2000);
SET @stmt = \'
  BULK I         


        
11条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 10:31

    I have a CSV file that I import using Bulk

    You need to create one table and all columns should be nullable and remove space in the last row, add only those columns that available in excel. And please do not create a primary column, this process is not Identity increment automatically that's why creating the error.

    I have done a bulk insert like this:

    CREATE TABLE [dbo].[Department](
        [Deptid] [bigint] IDENTITY(1,1) NOT NULL,
        [deptname] [nvarchar](max) NULL,
        [test] [nvarchar](max) NULL,
     CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED 
    (
        [Deptid] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
        ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    
    CREATE TABLE [dbo].[Table_Column](
        [column1] [nvarchar](max) NULL,
        [column2] [nvarchar](max) NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    
    BULK INSERT Table_Column
    FROM 'C:\Temp Data\bulkinsert1.csv'
    WITH (
        FIELDTERMINATOR = ',',
        ROWTERMINATOR='\n' ,
        batchsize=300000 
    );
    
    insert into [dbo].[Department] 
    select column1,column2 from Table_Column
    

提交回复
热议问题