sql server 2016用fmt导入utf-8 csv文件

时间:2017-05-18 11:20:43

标签: sql-server utf-8

我需要将utf-8(无BOM)CSV文件导入SQL Server 2016

这里有一个内容示例: enter image description here

使用以下查询

BULK INSERT [test].[dbo].[csv_test]
FROM 'C:\inetpub\wwwroot\test\16052017.csv'
WITH
(
  FIELDTERMINATOR = ','
  ,ROWTERMINATOR = '\n'
  ,BATCHSIZE      = 50000
  ,DATAFILETYPE = 'widechar'
  ,CODEPAGE       = '65001'
  ,FIRSTROW       = 2
  ,TABLOCK
)

由于我有几个不同的文件,我打算使用相同的存储过程并为每个不同的文件使用特定的格式文件,所以我只应“翻译”上面的过程,我这样做了:

BULK INSERT [test].[dbo].[csv_test]
FROM 'C:\inetpub\wwwroot\test\16052017.csv'
WITH 
( 
    FORMATFILE = 'C:\csv_test.fmt', 
    FIRSTROW = 2 ,
    DATAFILETYPE = 'widechar',
    CODEPAGE       = '65001'
)

其中csv_test.fmt是:

    13.0
    13
    1       SQLNCHAR             0       1000     ","     1    RegisteredItemN             Latin1_General_100_CI_AS
    2       SQLNCHAR             0       1000     ","     2    CountryOfDestination        Latin1_General_100_CI_AS
    3       SQLNCHAR             0       1000     ","     3    Customer                    Latin1_General_100_CI_AS
    4       SQLNCHAR             0       1000     ","     4    Identifier                  Latin1_General_100_CI_AS
    5       SQLNCHAR             0       1000     ","     5    Freight                     Latin1_General_100_CI_AS
    6       SQLNCHAR             0       1000     ","     6    HAWB                        Latin1_General_100_CI_AS
    7       SQLNCHAR             0       1000     ","     7    MAWB                        Latin1_General_100_CI_AS
    8       SQLNCHAR             0       1000     ","     8    Name                        Latin1_General_100_CI_AS
    9       SQLNCHAR             0       1000     ","     9    Address                     Latin1_General_100_CI_AS
    10      SQLNCHAR             0       1000     ","    10    Postcode                    Latin1_General_100_CI_AS
    11      SQLNCHAR             0       1000     ","    11    City                        Latin1_General_100_CI_AS
    12      SQLNCHAR             0       1000     ","    12    Weight                      Latin1_General_100_CI_AS
    13      SQLNCHAR             0       1000     "\n"   13    Connote                     Latin1_General_100_CI_AS

但是我收到了这个错误:

    Bulk load data conversion error (truncation) for row 2, column 3 (Customer).

    The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
    Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

有什么不对?

0 个答案:

没有答案