page contents

About the Post

Author Information

HOW TO: Import CSV Data files into SQL Server

How many times have we had to perform an inventory of either our equipment or software assets and then get asked to import that information into a database of some sort?

Recently a friend at work asked me for some assistance on creating such a database to inventory server hardware. Lucky for me they had most of the data fields input taken care of and to add to that luck, they were scanning bar codes and dumping the data into Microsoft Excel. I made a suggestion at that point to save the data as CSV files and then we can quickly input the data into Microsoft SQL Server.

In this article, I am going to walk you through the process of creating the database, importing the data from the CSV file and then adding more information from an additional CSV file. In this scenario, I am going to create a database called Inventory using TSQL command: CREATE DATABASE [Inventory]


Then I am going to locate my CSV files that I will use to demo this import:

Now, we can right-click on the newly created database, go to Tasks, then Import data:

It will generate this Wizard to walk you through the import:

Now, we can select the data source we wish to use, which in this case is a Flat File Source:

We will browse to the file

Then select file (ensure you either choose all files or CSV files)

You can also preview how the import will look as well before you actually do it:


Configure how you want to import the database, server and connections:

You can also change the table name as well, other wise it will take on the name of the file it is importing from:

Then you can run the package now to import:

Confirm your selections and then select finish and you are on your way:

Then you can verify the import in SQL Server, by expanding your database, then tables and then Select Top 1000 rows

As you can see the fields are the same as what we saw in the CSV file in Microsoft Excel. The last step is updating the inventory database from another scan, say we have another person using this method at another location and we want to update their data into our database. It is the same process as listed above, but you will need to check mark what is highlighted below:

Basically it will tell the import to skip the top column, which is used mostly as a header:

 And there you have it, an easy import of data into a new user database for you to keep track of your assets. As usual, I hope this information helps.

Tags: , , , , , ,

One Response to “HOW TO: Import CSV Data files into SQL Server”

  1. MyNameIS2012 #

    thank you for this tutorial ^^, but what if we have a column with float type?

    April 23, 2013 at 7:12 AM
Copy Protected by Chetan's WP-Copyprotect.