How to write UTF-8 characters using bulk insert in SQL Server?(如何在 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.
这篇关于如何在 SQL Server 中使用批量插入编写 UTF-8 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 SQL Server 中使用批量插入编写 UTF-8 字符?


- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- SQL 临时表问题 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01