5

I have several files about 15k each of CSV data I need to import into SQL Server 2005.

What would be the simplest way to import the csv data into sql server? Ideally, the tool or method would create the table as well, since there are about 180 fields in it, this would simplify things.

3 Answers 3

10

BULK INSERT is your friend. Something like:

BULK INSERT MyTable 
    FROM 'c:\data.csv' 
    WITH 
    ( 
        FIELDTERMINATOR = ',', 
        ROWTERMINATOR = '\n' 
    )

EDIT

Although BULK INSERT will not create the table for you. You could look at using SQL Server Integration Services, which will infer the schema from the data file. Take a look at http://www.kodyaz.com/articles/import-csv-flat-file-into-sql-server-using-ssis-integration-services.aspx as an example.

Sign up to request clarification or add additional context in comments.

Comments

4

Use the Import and Export tool in SQL Server. Should be under programs -> SQL Server 2005 -> Import and Export (32) & Import and Export (64)

1 Comment

Couldn't see that option for 2005/8/12 (I have all three installed) is it an add-on or option on install?
2

You can use MSSQL wizard: 1) Select your database from MSSql Menagement Studio, right click on it and select "tasks" 2) under tasks you'll find "import data", on the new window click next 3) select in data source "flat file source" to import csv and then follow the wizard.

in my experience sometimes csv arn't imported correctly so, if you can, convert it in excel file and in data source select "microsoft excel"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.