I have 6 million rows of data that I want to insert into my SQL Server database. I can do it the slow way with 6 million INSERT statements (I estimate it will take 18 hours), or I can try BULK INSERT.
BULK INSERT has problems with the inability to escape characters, but the data in this case is very simple and therefore should not run into this problem.
However, SQL Server does not seem to want to insert any date / time data into the field.
Here is the table (psuedo-SQL)
CREATE TABLE Tasks ( TaskId bigint NOT NULL IDENTITY(1,1) PRIMARY KEY, TriggerId bigint NOT NULL FOREIGN KEY, Created datetime NOT NULL, Modified datetime NOT NULL, ScheduledFor datetime NULL, LastRan datetime NULL,
Here is my BULK INSERT statement:
SET DATEFORMAT dmy BULK INSERT Tasks FROM 'C:\TasksBulk.dat' WITH ( -- CHECK_CONSTRAINTS is not necessary as the only constraints are always enforced regardless of this option (UNIQUE, PRIMARY KEY, and NOT NULL) CODEPAGE = 'RAW', DATAFILETYPE = 'native', KEEPIDENTITY, MAXERRORS = 1, ORDER ( CallId ASC ), FIELDTERMINATOR = '\t', ROWTERMINATOR = '\0' )
And here is the first row of data in TasksBulk.dat:
1000\t1092\t01/01/2010 04:00:17\t01/01/2010 04:00:17\t\t01/01/2010 04:00:14\0
(For readability, reformatted with tabs replaced with 4 spaces :)
1000 1092 01/01/2010 04:00:17 01/01/2010 04:00:17 01/01/2010 04:00:14\0
However, when I run the BULK INSERT statement, I get this error:
Msg 4864, Level 16, State 1, Line 2 Bulk upload data conversion error (type mismatch or invalid character for the specified code page) for line 1, column 3 (created).
I tried to use different terminators for strings and fields and every other date / time format (including the "01/01/2010", "2010-01-01", with or without the "04:00:17" component). I do not know what I am doing wrong here.