Import CSV File Into SQL Server Using Bulk Insert

by Prashant 26. May 2009 00:51

You have large data to import to SQL Server, and you have all the data in a CSV File (Comma Seperated Value file). Are you going to map the field one by one? 

OR just use a small function od SQL to import everything in the table. But before you proceed with this you need to map each column of CSV with the one with your table column. Look at the below quick example on how to use the BULK INSERT to import CSV file data into SQL Server.

Step 1: Create a CSV file.

Step 2: Create a table and map the fields accordingly: (Check below screenshot)

 

Here is the CODE:

BULK INSERT TestTable
FROM 'c:\TestData.csv'  -- Full path of the CSV file
WITH
(
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n'   --Use to shift the control to next row
)

 

Share or Bookmark this post…
  • Live
  • Facebook
  • TwitThis
  • del.icio.us
  • Digg
  • DZone
  • Technorati
  • StumbleUpon
  • Google
  • E-Mail

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , ,

T-SQL

Powered by BlogEngine.NET 1.5.0.7
Visit blogadda.com to discover Indian blogs

About

Name of authorMy name is Prashant Khandelwal. I am a .NET programmer and technology enthusiast from New Delhi, India.

       

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2010

Creative Commons License