gpt4 book ai didi

sql-server - 了解 SQL Server 排序规则中的 Unicode 和代码页

转载 作者:行者123 更新时间:2023-12-03 13:14:35 24 4
gpt4 key购买 nike

为什么所有 SQL Server 2008 R2 排序规则都与代码页相关联。所有排序规则都是 unicode 吗?

当我们的数据库被使用不同代码页的多种语言使用时,如何选择排序规则?

谢谢你。

最佳答案

CHAR vs. NCHAR(即非Unicode vs. Unicode)定义了字符存储编码。排序规则定义...排序规则(即排序顺序和比较规则)。它们是不同的概念,尽管经常混淆。

混淆源于这样一个事实,即客户端工具使用非 Unicode 数据的排序规则作为选择数据代码页的提示。见 Code Page Architecture .这意味着像 ADO.Net SqlClient 这样的客户端可以将从服务器接收的单字节 CHAR 数据正确编码为多字节 string .Net 对象。列元数据将包含使用的排序规则,因此客户端将知道如何根据特定代码页解释单字节数据。

对于 Unicode (NCHAR) 列,客户端不需要根据代码页来解释数据,数据本身已经是多字节的,客户端将根据 UCS-2 编码(所使用的 Unicode 的实际风格)来解释它SQL 服务器)。

但是,不要将此与实际的排序规则混淆:比较字符的规则。如 Working with Collations 中所述:

an English speaker would expect the character string 'Chiapas' to come before 'Colima' in ascending order. However, a Spanish speaker in Mexico might expect words beginning with 'Ch' to appear at the end of a list of words starting with 'C'. Collations dictate these kinds of sorting and comparison rules. The Latin_1 General collation will sort 'Chiapas' before 'Colima' in an ORDER BY ASC clause, whereas the Traditional_Spanish collation will sort 'Chiapas' after 'Colima'.



此排序规则适用于任何数据类型(CHAR 非 Unicode 或 NCHAR Unicode)。

关于sql-server - 了解 SQL Server 排序规则中的 Unicode 和代码页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15546213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com