开发者

Create a new table and import data from csv file into SQL Server 2005

开发者 https://www.devze.com 2022-12-30 19:24 出处:网络
I have se开发者_StackOverflow中文版veral files about 15k each of CSV data I need to import into SQL Server 2005.

I have se开发者_StackOverflow中文版veral 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.


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.


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


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"

0

精彩评论

暂无评论...
验证码 换一张
取 消