Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Column is too long" error with BULK INSERT

I am trying to run the following command to bulk insert data from a CSV file--

 BULK INSERT TestDB.dbo.patent  FROM 'C:\1patents.csv'  WITH (FIRSTROW = 1,  FIELDTERMINATOR = '^', ROWTERMINATOR='\n'); 

The error I am getting is this--

Msg 4866, Level 16, State 1, Line 1
The bulk load failed. The column is too long in the data file for row 1, column 6.
Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

Now this is the data in the first row--

 00000001^^18360713^295^4^0 

And in the table the last field (corresp. to the 6th column of data above = 0) is of type 'int'.

What am I doing wrong here? Why am I getting the above error?

like image 606
Arvind Avatar asked Jan 16 '13 18:01

Arvind


People also ask

What is Fieldterminator =' in SQL?

Specifies that the data fields be loaded as character data. FIELDTERMINATOR =' , ' Specifies a comma ( , ) as the field terminator. ROWTERMINATOR =' \n ' Specifies the row terminator as a newline character.

What is codepage in bulk insert?

The CODEPAGE option is used when you need to load extended characters (values greater than 127); this option allows you to specify one of the following values for char, varchar, and text datatypes: ACP. Convert from the ANSI/Microsoft Windows code page (ISO 1252) to the SQL Server code page. OEM.

How can I speed up bulk insert in SQL?

Below are some good ways to improve BULK INSERT operations : Using TABLOCK as query hint. Dropping Indexes during Bulk Load operation and then once it is completed then recreating them. Changing the Recovery model of database to be BULK_LOGGED during the load operation.


2 Answers

I got extraction from Oracle/Unix. I replaced \r\n by ROWTERMINATOR = '0x0a' and it worked for me.
Thanks a lot !

like image 83
Fabien Cousin Avatar answered Sep 18 '22 12:09

Fabien Cousin


Like answered above, I had the same problem importing a csv file into SQL Server. I was using ROWTERMINATOR = '\n' and I also tried to use '\r\n' and '\r'. None of them worked.

But when using ROWTERMINATOR = '0x0a' the table loaded without problems.

I don't know the "why?" behind this, hopefully somebody else can shed light over it.

like image 26
comendeiro Avatar answered Sep 16 '22 12:09

comendeiro