A code page is a character set, which can include numbers, punctuation marks, and other glyphs. Different languages and locales may use different code pages. For example, ANSI code page 1252 is used for English and most European languages; OEM code page 932 is used for Japanese Kanji.
A code page can be represented in a table as a mapping of characters to single-byte values or multibyte values. Many code pages share the ASCII character set for characters in the range 0x00 – 0x7F.
The Microsoft run-time library uses the following types of code pages:
System-default ANSI code page. By default, at startup the run-time system automatically sets the multibyte code page to the system-default ANSI code page, which is obtained from the operating system. The call:
setlocale ( LC_ALL, "" );
also sets the locale to the system-default ANSI code page.
Locale code page. The behavior of a number of run-time routines is dependent on the current locale setting, which includes the locale code page. (For more information, see Locale-Dependent Routines.) By default, all locale-dependent routines in the Microsoft run-time library use the code page that corresponds to the "C" locale. At run-time you can change or query the locale code page in use with a call to setlocale.
Multibyte code page. The behavior of most of the multibyte-character routines in the run-time library depends on the current multibyte code page setting. By default, these routines use the system-default ANSI code page. At run-time you can query and change the multibyte code page with _getmbcp and _setmbcp, respectively.
The "C" locale is defined by ANSI to correspond to the locale in which C programs have traditionally executed. The code page for the "C" locale ("C" code page) corresponds to the ASCII character set. For example, in the "C" locale, islower returns true for the values 0x61 – 0x7A only. In another locale, islower may return true for these as well as other values, as defined by that locale.
SQL Server 2000 支持在一个数据库中存储具有不同排序规则的对象。可为一直到列级的各级别指定不同的 SQL Server 2000 排序规则。可为表中的每列指派不同的排序规则。SQL Server 的早期版本仅支持每个 SQL Server 实例有一个排序规则。在 SQL Server 7.0 或更早的版本实例中创建的所有数据库和数据库对象具有相同的排序规则。
字符数据的存储方式
在计算机中,字符由不同的位模式(ON 或 OFF)表示。每个字节有 8 位,这 8 位可以有 256 种不同的 ON 和 OFF 组合模式。对于使用 1 个字节存储每个字符的程序,通过给每个位模式指派字符可表示最多 256 个不同的字符。2 个字节有 16 位,这 16 位可以有 65,536 种唯一的 ON 和 OFF 组合模式。使用 2 个字节表示每个字符的程序可表示最多 65,536 个字符。
单字节代码页是字符定义,这些字符映射到每个字节可能有的 256 种位模式中的每一种。代码页定义大小写字符、数字、符号以及 !、@、#、% 等特殊字符的位模式。每种欧洲语言(如德语和西班牙语)都有各自的单字节代码页。虽然用于表示 A 到 Z 拉丁字母表字符的位模式在所有的代码页中都相同,但用于表示重音字符(如"é"和"á")的位模式在不同的代码页中却不同。如果在运行不同代码页的计算机间交换数据,必须将所有字符数据由发送计算机的代码页转换为接收计算机的代码页。如果源数据中的扩展字符在接收计算机的代码页中未定义,那么数据将丢失。如果某个数据库为来自许多不同国家的客户端提供服务,则很难为该数据库选择这样一种代码页,使其包括所有客户端计算机所需的全部扩展字符。而且,在代码页间不停地转换需要花费大量的处理时间。
在运行 Microsoft Windows® 操作系统的计算机上,操作系统和 Windows 应用程序使用的代码页由 Windows 区域设置定义。区域设置是在安装操作系统时选择的。Windows 应用程序使用由 Windows 区域设置定义的代码页来解释数据。Windows 应用程序还支持宽字符数据,即 Unicode 数据。
非 Unicode 字符数据类型 char、varchar 和 text。这些数据类型使用单字节或双字节代码页中定义的字符表示法。
有关字符数据的存储方式以及代码页、Unicode 和排序次序操作的更多信息,请参见在 http://msdn.microsoft.com MSDN® 页中的 Developing International Software for Windows 95 and Windows NT 4.0。
SQL Server 2000 将所有的文本化系统目录数据都存储在包含 Unicode 数据类型的列中。数据库对象(如表、视图和存储过程)的名称存储在 Unicode 列中。这样就可以只使用 Unicode 开发应用程序,从而避免了所有的代码页转换问题。
排序次序
排序次序指定 SQL Server 解释、排序、比较和显示字符数据所使用的规则。例如,排序次序定义"a"是小于、等于还是大于"b"。排序次序定义排序规则是否区分大小写,例如"m"和"M"是否相同。另外还定义排序规则是否区分重音,例如"á"和"ä"是否相同。
SQL Server 2000 对每种排序规则使用两种排序次序,一种用于 Unicode 数据,另一种用于字符代码页。
许多 SQL Server 排序规则使用相同的代码页,但是代码页的排序次序不同。这使站点得以选择:
是否仅根据位模式所表示的数字值来排序字符。二进制排序的速度最快,这是因为 SQL Server 不用做任何调整并可使用快速、简单的排序算法。二进制排序次序始终区分大小写。由于代码页中的位模式可能不按照特定语言的字典规则所定义的序列排列,二进制排序有时并不按照使用该语言的用户所期待的序列对字符进行排序。