具有 Latin1 代码页的 SQL Server 数据库将日语字符显示为“?”

发布于 2024-10-05 18:45:11 字数 809 浏览 0 评论 0原文

以下场景的三个问题:

  • 具有 Latin1 代码页并显示“?”的 SQL Server 2005 生产数据库Management Studio 中的无效字符。
  • SomeCompanyApp 客户端作为一项服务,填充来自服务器和工作站的数据。
  • SomeCompanyApp 管理控制台显示“?”对于亚洲字符。

由于这是一个产品数据库,我不会写入它。

我不知道将数据存储在数据库中的客户端应用程序是否实际上将其正确存储为 Unicode,并且它只是不显示,因为它们使用 Latin1 作为控制台。

Q1:据我了解,SQL Server 将 nvarchar 文本存储为 Unicode,无论代码页如何,还是我完全错了,如果代码页是 Latin1,那么该代码页中不存在的所有内容都会转换为“?” 。

Q2:和文本栏一样吗?

Q3:有没有办法使用 SQL Server Management Studio 或 Visual Studio 和一些代码(不关心哪种语言:))来查询数据库并显示字符是否确实显示为日语、中文、韩文等?

我的最终目标是从数据库中提取数据并使用 UTF-8 将其存储在另一个数据库中,以将日语和其他亚洲字符显示为我自己的客户端 Web 应用程序中的内容。 我会满足于 Q3 的答案。我可以用多种语言进行编码,并且至少能理解其他一些语言,但我对 Unicode 的了解还不够。如果您想知道我的网络应用程序将使用 pyodbc 和 cassandra,但对于这些问题并不重要。

Three questions with the following scenario:

  • SQL Server 2005 production db with a Latin1 codepage and showing "?" for invalid chars in Management Studio.
  • SomeCompanyApp client as a service that populates the data from servers and workstations.
  • SomeCompanyApp management console that shows "?" for Asian characters.

Since this is a prod db I will not write to it.

I don't know if the client app that is storing the data in the database is actually storing it correctly as Unicode and it simply doesn't show because they are using Latin1 for the console.

Q1: As I understand it, SQL Server stores nvarchar text as Unicode regardless of the codepage or am I completely wrong and if the codepage is Latin1 then everything that is not in that codepage gets converted to "?".

Q2: Is it the same with a text column?

Q3: Is there a way using SQL Server Management Studio or Visual Studio and some code (don't care which language :)) to query the db and show me if the chars really do show up as Japanese, Chinese, Korean, etc.?

My final goal is to extract data from the db and store it in another db using UTF-8 to show Japanese and other Asian chars as what they are in my own client webapp. I will settle for an answer to Q3. I can code in several languages and at the very least understand some others but I'm just not knowledgeable enough about Unicode. In case you want to know my webapp will be using pyodbc and cassandra but for these questions that doesn't matter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此生挚爱伱 2024-10-12 18:45:11

当插入到 SSMS 中的 NVARCHAR 列时,您需要绝对确保您的字符串带有 N 前缀:

工作:

 INSERT INTO dbo.MyTable(NVarcharColumn) VALUES('Some Text with Special Char')

SQL Server 将解释您的字符串在 VALUES(..) 中作为 VARCHAR,从而去除所有特殊字符。

您需要这个

 INSERT INTO dbo.MyTable(NVarcharColumn) VALUES(N'Some Text with Special Char')

在文本文字前面加上N'..' 告诉 SQL Server 将其始终视为 NVARCHAR。

这可以帮助您解决 Q3 问题吗?

When inserting into an NVARCHAR column in SSMS, you need to make absolutely sure you're prefixing your string with a N:

This will NOT work:

 INSERT INTO dbo.MyTable(NVarcharColumn) VALUES('Some Text with Special Char')

SQL Server will interpret your string in the VALUES(..) as VARCHAR and thus strip off any special characters.

You need this:

 INSERT INTO dbo.MyTable(NVarcharColumn) VALUES(N'Some Text with Special Char')

Prefixing your text literal with an N'..' tells SQL Server to treat this as NVARCHAR all the way.

Does this help you solve your Q3 ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文