在 TSQL 中的函数参数前面放一个“N"的目的是什么? [英] What is the purpose of putting an 'N' in front of function parameters in TSQL?
问题描述
在 TSQL 中在函数参数前面放一个N"的目的是什么?
What is the purpose of putting an 'N' in front of function parameters in TSQL?
比如下面代码中函数参数前面的N
是什么意思:
For example, what does the N
mean in front of the function parameter in the following code:
object_id(N'dbo.MyTable')
推荐答案
它表示一个国家化"的 unicode 字符串常量.
It indicates a "nationalized" a.k.a. unicode string constant.
http://support.microsoft.com/kb/239530
在 SQL Server 中处理 Unicode 字符串常量时,必须在所有 Unicode 字符串前面加上大写字母 N,如 SQL Server 联机丛书主题使用 Unicode 数据"中所述.
When dealing with Unicode string constants in SQL Server you must precede all Unicode strings with a capital letter N, as documented in the SQL Server Books Online topic "Using Unicode Data".
http://msdn.microsoft.com/en-us/library/aa276823%28SQL.80%29.aspx
nchar
和 nvarchar
固定长度 (nchar) 或可变长度 (nvarchar) Unicode 数据并使用 UNICODE UCS-2 字符集的字符数据类型.
Character data types that are either fixed-length (nchar) or variable-length (nvarchar) Unicode data and use the UNICODE UCS-2 character set.
nchar(n)
n 个字符的定长 Unicode 字符数据.n 必须是 1 到 4,000 之间的值.存储大小是 n 字节的两倍.nchar
的 SQL-92 同义词是国家字符和国家字符.
Fixed-length Unicode character data of n characters. n must be a value from 1 through 4,000. Storage size is two times n bytes. The SQL-92 synonyms for nchar
are national char and national character.
nvarchar(n)
n 个字符的可变长度 Unicode 字符数据.n 必须是 1 到 4,000 之间的值.存储大小(以字节为单位)是输入字符数的两倍. 输入的数据长度可以为 0 个字符.nvarchar
的 SQL-92 同义词是 national char 变化和国家字符变化.
Variable-length Unicode character data of n characters. n must be a value from 1 through 4,000. Storage size, in bytes, is two times the number of characters entered. The data entered can be 0 characters in length. The SQL-92 synonyms for nvarchar
are national char varying and national character varying.
这篇关于在 TSQL 中的函数参数前面放一个“N"的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!