使用格式文件将数据批量插入SQL Server

时间:2018-10-05 05:14:11

标签: sql-server bulkinsert

在通过格式文件批量插入数据时,我很难定义字段终止符。我要上传的csv如下所示:

"Prabhat",4,"Math",02/10/2013,25,"Test data for prabhat."
"Murari",5,"Science",02/11/2013,24,"Test data for his's test, where we can test 2nd ROW, Test."
"sanjay",4,"Science",,25,"Test Only."
"xyz",5,"Science,",,,""

我正在使用的格式文件如下:

12.0
6
1   SQLCHAR   0  8000  "\","      1     Name          SQL_Latin1_General_CP1_CI_AS
2   SQLCHAR   0  40    ",\""      2     Class         SQL_Latin1_General_CP1_CI_AS
3   SQLCHAR   0  40    "\","     3     Subject       SQL_Latin1_General_CP1_CI_AS
4   SQLCHAR   0  40    ","      4     ExamDate      SQL_Latin1_General_CP1_CI_AS
5   SQLCHAR   0  40    ",\""      5     Mark          SQL_Latin1_General_CP1_CI_AS
6   SQLCHAR   0  1000  "\"\r\n" 6    Description   SQL_Latin1_General_CP1_CI_AS

我无法从第一列中删除",如您在下面的上传数据表中所见:

+----------+-------+----------+------------+------+------------------------------------------------------------+
|   Name   | Class | Subject  |  ExamDate  | Mark |                        Description                         |
+----------+-------+----------+------------+------+------------------------------------------------------------+
| "Prabhat |     4 | Math     | 10/02/2013 | 25   | Test data for prabhat.                                     |
| "Murari  |     5 | Science  | 11/02/2013 | 24   | Test data for his's test, where we can test 2nd ROW, Test. |
| "sanjay  |     4 | Science  | NULL       | 25   | Test Only.                                                 |
| "xyz     |     5 | Science, | NULL       | NULL | NULL                                                       |
+----------+-------+----------+------------+------+------------------------------------------------------------+

我无法弄清楚如何更改格式文件以从表的第一列中删除",该表已使用批量插入查询上传到SQL Server。

0 个答案:

没有答案