SQL Server批量插入rowterminator失败

时间:2015-10-12 12:35:15

标签: sql-server

我有这样的csv:

"F","003","abc""X","1","50A1","name","Z5AA1A005C","70008","","A1ZZZZ17","","","","","","""X","2","50A1","name","Z5AA1A005C","70007","","A1ZZZZ17","","","","","","""X","3","50A1","name","Z5AA1A005C","70000","","A1ZZZZ17","","","","","",""

我需要批量插入表格A 从第2行开始

BULK INSERT A FROM 'c:\csvtest.csv' 
  WITH
  ( 
   FIELDTERMINATOR='","',
   ROWTERMINATOR='0x0a',
   FIRSTROW = 2,
   DATAFILETYPE = 'widenative'
  )

问题是我插入时插入失败 它显示错误:

  

Msg 4866,Level 16,State 8,Line 15批量加载失败。专栏   在第1行第15列的数据文件中太长。验证是否   字段终止符和行终止符是正确指定的。消息7301,   16级,状态2,行15无法获得所需的接口   (“IID_IColumnsInfo”)来自OLE DB提供程序“BULK”,用于链接服务器   “(空)”。

我尝试过rowterminator:'0x0a','\ n','\ r \ n','char(10)'但没有任何作用

2 个答案:

答案 0 :(得分:0)

虽然它只会从第2行第1行插入数据,但仍然需要采用正确的格式,因为我非常确定SQLServer会执行“预验证”。循环使用Schema以确保数据有一半的机会进入数据库。第1行未通过此预验证'因为您没有按照表架构提供所有列。

答案 1 :(得分:0)

尝试在记事本中打开文件,然后检查它是否有线结构并再次保存。