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 字符?
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
