创建一个新表并将数据从csv文件导入到SQL Server 2005中 [英] Create a new table and import data from csv file into SQL Server 2005

查看:519
本文介绍了创建一个新表并将数据从csv文件导入到SQL Server 2005中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个文件,大约15k每个CSV数据我需要导入到SQL Server 2005。

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

将csv数据导入sql是最简单的方法服务器?理想情况下,工具或方法也会创建表,因为它有大约180个字段,这将简化操作。

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.

推荐答案

p> BULK INSERT 是您的朋友。像:

BULK INSERT is your friend. Something like:

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

EDIT

虽然 BULK INSERT 为您创建表。您可以查看使用SQL Server集成服务,它将从数据文件中推断出模式。请查看 http://www.kodyaz.com/articles/import-csv-flat-file-into-sql-server-using-ssis-integration-services.aspx 作为示例。

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.

这篇关于创建一个新表并将数据从csv文件导入到SQL Server 2005中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆