什么时候应该使用 SQL Server Unicode 'N' 常量? [英] When should I use the SQL Server Unicode 'N' Constant?

查看:21
本文介绍了什么时候应该使用 SQL Server Unicode 'N' 常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究如何在我的代码中使用 Unicode 'N' 常量,例如:

I've been looking into the use of the Unicode 'N' constant within my code, for example:

select object_id(N'VW_TABLE_UPDATE_DATA', N'V');

insert into SOME_TABLE (Field1, Field2) values (N'A', N'B');

在阅读了何时使用它之后,我仍然不完全清楚在什么情况下应该和不应该使用它.

After doing some reading around when to use it, and I'm still not entirely clear as to the circumstances under which it should and should not be used.

是否像在数据类型或参数需要 unicode 数据类型时使用它一样简单(如上述示例所示),还是比这更复杂?

Is it as simple as using it when data types or parameters expect a unicode data type (as per the above examples), or is it more sophiticated than that?

以下微软网站给出了解释,但我也有点不清楚它使用的一些术语http://msdn.microsoft.com/en-us/library/ms179899.aspx

The following Microsoft site gives an explanation, but I'm also a little unclear as to some of the terms it is using http://msdn.microsoft.com/en-us/library/ms179899.aspx

或者准确地说:

Unicode 常量被解释为Unicode 数据,并且不被评估使用代码页.Unicode 常量做一个整理.这个整理主要控制比较和区分大小写.Unicode 常量被分配了默认的排序规则当前数据库,除非COLLATE 子句用于指定一个整理.

Unicode constants are interpreted as Unicode data, and are not evaluated by using a code page. Unicode constants do have a collation. This collation primarily controls comparisons and case sensitivity. Unicode constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation.

这是什么意思:

  • 使用代码页进行评估"?
  • 整理?

我意识到这是一个相当广泛的问题,但任何链接或帮助将不胜感激.

I realise this is quite a broad question, but any links or help would be appreciated.

谢谢

推荐答案

当数据类型或参数需要 unicode 数据类型时,是否像使用它一样简单?

差不多.

回答您的其他问题:

代码页 是字符集编码的另一个名称.例如,windows 代码页 1255 编码希伯来语.这通常用于字符的 8 位编码.就您的问题而言,字符串可能会使用不同的代码页进行评估(因此,相同的位模式可能会被解释为日语字符或阿拉伯字符,具体取决于用于评估它的代码页).

A code page is another name for encoding of a character set. For example, windows code page 1255 encodes Hebrew. This is normally used for 8bit encodings for characters. In terms of your question, strings may be evaluated using different code pages (so the same bit pattern may be interpreted as a Japanese character or an Arabic one, depending on what code page was used to evaluate it).

Collat​​ion 是关于 SQL Server 如何对字符串进行排序 -这取决于代码页,因为您会以不同的方式对不同语言的字符串进行排序.请参阅这篇文章一个例子.

Collation is about how SQL Server is to order strings - this depends on code page, as you would order strings in different languages differently. See this article for an example.

这篇关于什么时候应该使用 SQL Server Unicode 'N' 常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆