Recommended method to import a .csv file into Microsoft SQL Server 2008 R2?

前端 未结 6 1010
陌清茗
陌清茗 2021-01-02 04:21

What is your recommended way to import .csv files into Microsoft SQL Server 2008 R2?

I\'d like something fast, as I have a directory with a lot of .csv files (>500MB

6条回答
  •  没有蜡笔的小新
    2021-01-02 04:55

    Using BULK INSERT in a T-SQL script seems to be a good solution.

    http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/

    You can get the list of files in your directory with xp_cmdshell and the dir command (with a bit of cleanup). In the past, I tried to do something like this with sp_OAMethod and VBScript functions and had to use the dir method because I had trouble getting the list of files with the FSO object.

    http://www.sqlusa.com/bestpractices2008/list-files-in-directory/

提交回复
热议问题