我有這個CSV命名test.csv下面批量插入ROWTERMINATOR問題
1,"test user",,,4075619900,[email protected],"Aldelo for Restaurants","this is my deal",,"location4"
2,"joe johnson",,"32 bit",445555519,[email protected],"Restaurant Pro Express","smoe one is watching u",,"some location"
下面的內容是我的SQL文件做批量插入
USE somedb
GO
CREATE TABLE CSVTemp
(id INT,
name VARCHAR(255),
department VARCHAR(255),
architecture VARCHAR(255),
phone VARCHAR(255),
email VARCHAR(255),
download VARCHAR(255),
comments TEXT,
company VARCHAR(255),
location VARCHAR(255))
GO
BULK
INSERT CSVTemp
FROM 'c:\test\test.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '''+CHAR(124)+''+CHAR(10)+'''
)
GO
--Check the content of the table.
SELECT *
FROM CSVTemp
GO
但發生了什麼是它的唯一插入來自第二條記錄的一條記錄和所有信息正被插入到第一條記錄的位置字段中
id,name,department,architecture,phone,email,download,comments,company,location
1,"test user",NULL,NULL,4075619900,[email protected],"Aldelo for Restaurants","this is my deal",NULL,"""location4""2,""joe johnson"",,""32 bit"",445555519,[email protected],""Restaurant Pro Express"",""smoe one is watching u"",,""some location"""
我認爲問題是ROWTERMINATOR
但我想所有這些
ROWTERMINATOR = '\n'
ROWTERMINATOR = '\r\n'
ROWTERMINATOR = '\r'
和所有相同的結果...關於如何解決這一問題
我通過PHP
創造一個像 this的CSV任何想法
你試過'\ n \ r'嗎? CSV文件來自哪裏?是否有可能在行尾有一些非打印字符? –
我通過服務器上的php生成它...我將更新我的問題 – Trace
也許顯示您用於生成CR + LF的PHP。 –