Import CSV file into SQL Server

后端 未结 12 1687
梦谈多话
梦谈多话 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:39

    Import the file into Excel by first opening excel, then going to DATA, import from TXT File, choose the csv extension which will preserve 0 prefixed values, and save that column as TEXT because excel will drop the leading 0 otherwise (DO NOT double click to open with Excel if you have numeric data in a field starting with a 0 [zero]). Then just save out as a Tab Delimited Text file. When you are importing into excel you get an option to save as GENERAL, TEXT, etc.. choose TEXT so that quotes in the middle of a string in a field like YourCompany,LLC are preserved also...

    BULK INSERT dbo.YourTableName
    FROM 'C:\Users\Steve\Downloads\yourfiletoIMPORT.txt'
    WITH (
    FirstRow = 2, (if skipping a header row)
    FIELDTERMINATOR = '\t',
    ROWTERMINATOR   = '\n'
    )
    

    I wish I could use the FORMAT and Fieldquote functionality but that does not appear to be supported in my version of SSMS

提交回复
热议问题