Import CSV file into SQL Server

后端 未结 12 1642
梦谈多话
梦谈多话 2020-11-22 15:41

I am looking for help to import a .csv file into SQL Server using BULK INSERT and I have few basic questions.

Issues:

12条回答
  •  一生所求
    2020-11-22 16:18

    2) If the client create the csv from excel then the data that have comma are enclosed within " ... " (double quotes) [as the below example] so how do the import can handle this?

    You should use FORMAT = 'CSV', FIELDQUOTE = '"' options:

    BULK INSERT SchoolsTemp
    FROM 'C:\CSVData\Schools.csv'
    WITH
    (
        FORMAT = 'CSV', 
        FIELDQUOTE = '"',
        FIRSTROW = 2,
        FIELDTERMINATOR = ',',  --CSV field delimiter
        ROWTERMINATOR = '\n',   --Use to shift the control to next row
        TABLOCK
    )
    

提交回复
热议问题