表结构很简单,就3个字段
- SQL code
CREATE TABLE [dbo].[IP2ProxyIPCountry] ( [A] [nvarchar] (15) NOT NULL , [B] [char] (2) NOT NULL , [C] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]
csv文件里没有ABC这3字段,直接是数据的,都是类似这样的
"aa","bb","cc"
"dd","ee","ff"
"gg","hh","ii"
"jj","kk","ll"
...
然后我想配合数据格式化文件进行导入
- XML code
<?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="CharTerm" TERMINATOR="," MAX_LENGTH="15"/> <FIELD ID="2" xsi:type="CharTerm" TERMINATOR="," MAX_LENGTH="2"/> <FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\n" MAX_LENGTH="64"/> </RECORD> <ROW> <COLUMN SOURCE="1" NAME="A" xsi:type="nvarchar"/> <COLUMN SOURCE="2" NAME="B" xsi:type="char"/> <COLUMN SOURCE="3" NAME="C" xsi:type="nvarchar"/> </ROW></BCPFORMAT>
- SQL code
BULK INSERT 表FROM 'c:\1.csv'with (FORMATFILE='c:\1.xml');
这样出错。不知道怎么样在导入的同时把引号都去掉,弄了很久了,有人帮忙吗
------解决方案--------------------
- SQL code
BULK INSERT 库名..表名 FROM 'c:\1.txt' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' )