如何在 SQL Server 中使用批量插入写入 UTF-8 字符?

我正在对 sqlserver 进行 BULK INSERT,但它没有正确地将 UTF-8 字符插入数据库.数据文件包含这些字符,但在批量插入执行后数据库行包含垃圾字符.

I am doing a BULK INSERT into sqlserver and it is not inserting UTF-8 characters into database properly. The data file contains these characters, but the database rows contain garbage characters after bulk insert execution.

我的第一个嫌疑人是格式文件的最后一行:

My first suspect was the last line of the format file:

10.0
3
1 SQLCHAR  0  0  "{|}"  1 INSTANCEID ""
2 SQLCHAR  0  0  "{|}"  2 PROPERTYID ""
3 SQLCHAR  0  0  "[|]"  3 CONTENTTEXT "SQL_Latin1_General_CP1_CI_AS"

但是,在阅读 这官方页面在我看来,这实际上是SQL Server 2008版中插入操作读取数据文件的错误.我们使用的是2008 R2版.

But, after reading this official page it seems to me that this is actually a bug in reading the data file by the insert operation in SQL Server version 2008. We are using version 2008 R2.

这个问题的解决方案是什么,或者至少是一种解决方法?

What is the solution to this problem or at least a workaround?

推荐答案

你不能.您应该首先使用 N 类型的数据字段,将文件转换为 UTF-16,然后将其导入.数据库不支持 UTF-8.

You can't. You should first use a N type data field, convert your file to UTF-16 and then import it. The database does not support UTF-8.

相关文章