sql-server – SQL Server:set character set(not collat​​ion)

前端之家收集整理的这篇文章主要介绍了sql-server – SQL Server:set character set(not collat​​ion)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
sql Server中创建表时,如何设置字段的默认字符集?在 MySQL中,这样做:
CREATE TABLE tableName (
    name VARCHAR(128) CHARACTER SET utf8
) DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

请注意,我在这里设置了两个字符集.这是多余的,我添加了两种方式只是为了演示.

我也设置了整理,以证明整理是不同的.我不是要求整理整理. Most questions询问sql Server中的字符集和编码是否使用归类回答,这是不一样的.

解决方法

As stated in BOL

Each sql Server collation specifies three properties:

  • The sort order to use for Unicode data types (nchar,nvarchar,and ntext). A sort order defines the sequence in which characters are
    sorted,and the way characters are evaluated in comparison operations.
  • The sort order to use for non-Unicode character data types (char,varchar,and text).
  • The code page used to store non-Unicode character data.

上面的报价来自2000年的docs.下面也说明了这一点.

DECLARE @T TABLE 
(
     code TINYINT PRIMARY KEY,Arabic_CS_AS CHAR(1) COLLATE Arabic_CS_AS NULL,Cyrillic_General_CS_AS CHAR(1) COLLATE Cyrillic_General_CS_AS NULL,Latin1_General_CS_AS CHAR(1) COLLATE Latin1_General_CS_AS NULL
);

INSERT INTO @T(code) VALUES (200),(201),(202),(203),(204),(205)

UPDATE @T 
  SET Arabic_CS_AS=CAST(code AS BINARY(1)),Cyrillic_General_CS_AS=CAST(code AS BINARY(1)),Latin1_General_CS_AS=CAST(code AS BINARY(1))

SELECT * 
FROM @T

结果

code Arabic_CS_AS Cyrillic_General_CS_AS Latin1_General_CS_AS
---- ------------ ---------------------- --------------------
200  ب            И                      È
201  ة            Й                      É
202  ت            К                      Ê
203  ث            Л                      Ë
204  ج            М                      Ì
205  ح            Н                      Í

猜你在找的MsSQL相关文章