Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

Why does BULK INSERT insert data in random order?

Asked by Anne Bell Apr 16, 2021 5 views 1 answer
Share

About this question

I have a CSV file with 350,000 rows. Would like to insert data to the temporary table in the same order as is in the CSV file. I am trying to BULK INSERT using:

BULK INSERT ##AllRows FROM @FilePath WITH ( FIELDTERMINATOR = 'n' ) Unfortunately BULK INSERT inserts data in random order. My header in every execution is in a different row. I ran it on SQL Server 2016. Is there a possibility that in older versions of SQL Server order manner was different? Using the FIRSTROW option does not recognize the header as the first row of the file. The file does not have any column for which we can order. In the file always header is in the first row. It could be a coincidence but even with FIRSTROW=2, it is possible that my header will be in the table. I checked it. It looks like the more rows the CSV file contains the more chance that inserts to the table will be in random order. Why sql server bulk insert CSV files randomly?


Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.