我正在尝试使用Bulk Insert
和XML格式文件加载固定宽度的文本文件。我在另一个固定宽度上使用了相同的进程和XML文件,除了列数较少。
错误
Msg 4857, Level 16, State 1, Line 16
Line 4 in format file "\\PATHC\addr.xml": Attribute "type" could not be specified for this type.

SQL Server表
create table [dbo].[raw_addr](
address_number varchar(max),
addr_linel varchar(max),
addr_line2 varchar(max),
street_no varchar(max),
street_name varchar(max),
street_type varchar(max),
locality varchar(max),
[state] varchar(max),
country varchar(max),
postcode varchar(max)
);
SQL Server批量插入
BULK INSERT [dbo].[raw_addr] FROM '\\PATH\addr.txt'
WITH (
FORMATFILE = '\\PATH\addr.xml',
ROWTERMINATOR='\r\n');
XML代码:
<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance">
<RECORD>
<FIELD ID="1" xsi:type="CharFixed" LENGTH="9" />
<FIELD ID="2" xsi:type="CharFixed" LENGTH="50" />
<FIELD ID="3" xsi:type="CharFixed" LENGTH="50" />
<FIELD ID="4" xsi:type="CharFixed" LENGTH="10" />
<FIELD ID="5" xsi:type="CharFixed" LENGTH="50" />
<FIELD ID="6" xsi:type="CharFixed" LENGTH="10" />
<FIELD ID="7" xsi:type="CharFixed" LENGTH="30" />
<FIELD ID="8" xsi:type="CharFixed" LENGTH="3" />
<FIELD ID="9" xsi:type="CharFixed" LENGTH="30" />
<FIELD ID="10" xsi:type="CharTerm" TERMINATOR="\r\n" LENGTH="4" />
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="address_number" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="2" NAME="addr_linel" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="3" NAME="addr_line2" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="4" NAME="street_no" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="5" NAME="street_name" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="6" NAME="street_type" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="7" NAME="locality" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="8" NAME="state" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="9" NAME="country" xsi:type="SQLNVARCHAR" />
<COLUMN SOURCE="10" NAME="postcode" xsi:type="SQLNVARCHAR" />
</ROW>
</BCPFORMAT>
&#13;
示例TXT提取
001044057C/- XXXXXX XXXXXXX 0000
001295978XXXX 0000
0013974311 0000
00124485712 0000
0012390352 0000
0014720345 0000
0014792876 0000
000986525 ARABANOO GRENFELL NSW 2810
000986589 PO BOX XX KEMPSEY NSW 2440
000740594 'RUSSLEY' ABERDEEN NSW 2336
000311516 BUNYARA ABERDEEN NSW 2336
000298796 CAMBRIA ABERDEEN NSW 2336
000540611 HALCOMBE ABERDEEN NSW 2336
000513112 'LARK HILL' ABERDEEN NSW 2336
000612955 FAN HILL ABERMAIN NSW 2326
001109439 BRAYWOOD ADAMINABY NSW 2630
000460864 TARA ADAMINABY NSW 2630
000315297 ADAMSTOWN NSW 2289
000470057 COORUMBENE ADELONG NSW 2729
000491941 NACKI ADELONG NSW 2729
答案 0 :(得分:0)
我认为您的问题出在SQL语句中,请尝试删除ROWTERMINATOR。因为您在格式文件中指定它所以没有必要。