How to create and populate a table in a single step as part of a CSV import operation?

前端 未结 3 1604
悲&欢浪女
悲&欢浪女 2020-12-03 03:43

I am looking for a quick-and-dirty way to import CSV files into SQL Server without having to create the table beforehand and define its columns.

Each impo

3条回答
  •  一个人的身影
    2020-12-03 03:49

    Referencing SQLServerPedia, I think this will work:

    sp_configure 'show advanced options', 1;
    RECONFIGURE;
    GO
    sp_configure 'Ad Hoc Distributed Queries', 1;
    RECONFIGURE;
    GO
    
    select TerritoryID
          ,TotalSales
          ,TotalCost
    INTO CSVImportTable
    from openrowset('MSDASQL'
                   ,'Driver={Microsoft Access Text Driver (*.txt, *.csv)}'
                   ,'select * from C:\csvtest.CSV')
    

提交回复
热议问题