Learning never exhausts the mind
Home >  Coding > SQL > Importing CSV File Into SQL Server Using Bulk Insert

Published 15th March 2010 by

How to import CSV file into SQL Server or how to load CSV file into SQL Server table are two commonly asked questions that have an easy answer.

A CSV file is one that has one row per line, and column values separated with a common, which gives it the name Comma Separated Values. It does not necessarily have to be comma separated, it could be separated with tabs or some other delimiter. CSV files are almost universally supported and a good way of transporting database records between systems.

To import a CSV into SQL Server you must first create the table. In this example the table is called Products and has three columns, product sku, product name and product description.

  productSku VARCHAR(10),
  productName VARCHAR(20),
  productDescription VARCHAR(255),

The data I am going to load is stored in the file C:\Tutorials\SQLBulkInsertTest.csv, the contents of which are shown below.

ABC123,Test Product,This is a test product to test the bulk insert function
ABC987,Another Test Product,This is another test product
XYZ444,Yet Another Test,This is yet another test product for SQL Server

Now, to import this data into the test Products table, we are going to use the Bulk Insert command.

FROM 'C:TutorialsSQLBulkInsertTest.csv'

Where FIELDTERMINATOR is the character used to separate column values and ROWTERMINATOR is used to split records. In this case the defaults are to split values using a comma and new line marks the end of a record.

By viewing the table data now, we can see that the data has been successfully imported.

SELECT * FROM Products
ABC123Test ProductThis is a test product to test the bulk insert function
ABC987Another Test ProductThis is another test product
XYZ444Yet Another TestThis is yet another test product for SQL Server

Leave a Reply

Fields marked with * are mandatory.

We respect your privacy, and will not make your email public. Hashed email address may be checked against Gravatar service to retrieve avatars. This site uses Akismet to reduce spam. Learn how your comment data is processed.