CSV 文件的批量插入问题
Bulk Insert issues with CSV file
我正在尝试从 CSV 文件加载 SQL 服务器 table。
我的批量插入语句:
bulk insert ClassList from 'ClassList.csv'
with (
firstrow=2,
fieldterminator=',',
maxerrors=100,
keepnulls
);
大部分数据加载但不加载其中一个字段包含逗号的少数行,因此它们具有双引号分隔符 - 这里加载第 21 和 23 行但不加载第 22 行:
21,Blue or Lilac Smoke Adult,22,PER,
22,"Red, Tortie, Cream, Blue or Lilac Cream or Choc. Tortie Smoke Adult",23,PER,
23,AC Silver Tabby Adult,24,PER,
我的table:
Class_Number varchar(10) not null
Class_Description varchar(200) not null
Class_Order int not null
Section_ID varchar(10) not null
Judge_Initials varchar(10) null
使用 SSMS v17.2。
SQL 服务器详情:
Product Version: 13.0.4206.0
Product Name: SQL Server 2016
Product Level: SP1
Product Edition: Express Edition (64-bit)
您的 csv 源文件中似乎有“,”作为数据。类似的问题在下面回答 link -
sql server Bulk insert csv with data having comma
好的,上面 link 中的答案是我的软件版本中的 BULK LOAD 无法处理在某些字段周围包含引号的文件。我没有尝试查看引用所有字符字段是否可行。我重新保存为制表符分隔字段 (.txt),它加载得很好。
来自 MS 文档:
https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql
**Input file format options**
FORMAT = 'CSV'
Applies to: SQL Server 2017 CTP 1.1.
Specifies a comma separated values file compliant to the RFC 4180 standard.
FIELDQUOTE = 'field_quote'
Applies to: SQL Server 2017 CTP 1.1.
Specifies a character that will be used as the quote character in the CSV
file. If not specified, the quote character (") will be used as the quote
character as defined in the RFC 4180 standard.
FORMAT 选项不可接受,这可能是我问题的根源。
我正在尝试从 CSV 文件加载 SQL 服务器 table。
我的批量插入语句:
bulk insert ClassList from 'ClassList.csv'
with (
firstrow=2,
fieldterminator=',',
maxerrors=100,
keepnulls
);
大部分数据加载但不加载其中一个字段包含逗号的少数行,因此它们具有双引号分隔符 - 这里加载第 21 和 23 行但不加载第 22 行:
21,Blue or Lilac Smoke Adult,22,PER,
22,"Red, Tortie, Cream, Blue or Lilac Cream or Choc. Tortie Smoke Adult",23,PER,
23,AC Silver Tabby Adult,24,PER,
我的table:
Class_Number varchar(10) not null
Class_Description varchar(200) not null
Class_Order int not null
Section_ID varchar(10) not null
Judge_Initials varchar(10) null
使用 SSMS v17.2。
SQL 服务器详情:
Product Version: 13.0.4206.0
Product Name: SQL Server 2016
Product Level: SP1
Product Edition: Express Edition (64-bit)
您的 csv 源文件中似乎有“,”作为数据。类似的问题在下面回答 link -
sql server Bulk insert csv with data having comma
好的,上面 link 中的答案是我的软件版本中的 BULK LOAD 无法处理在某些字段周围包含引号的文件。我没有尝试查看引用所有字符字段是否可行。我重新保存为制表符分隔字段 (.txt),它加载得很好。
来自 MS 文档:
https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql
**Input file format options**
FORMAT = 'CSV'
Applies to: SQL Server 2017 CTP 1.1.
Specifies a comma separated values file compliant to the RFC 4180 standard.
FIELDQUOTE = 'field_quote'
Applies to: SQL Server 2017 CTP 1.1.
Specifies a character that will be used as the quote character in the CSV
file. If not specified, the quote character (") will be used as the quote
character as defined in the RFC 4180 standard.
FORMAT 选项不可接受,这可能是我问题的根源。