SQL 在 TSQL 中的函数参数前面放一个“N”的目的是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2448203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the purpose of putting an 'N' in front of function parameters in TSQL?
提问by Ben McCormack
What is the purpose of putting an 'N' in front of function parameters in TSQL?
在 TSQL 中的函数参数前面放一个“N”的目的是什么?
For example, what does the N
mean in front of the function parameter in the following code:
比如N
下面代码中函数参数前面的意思是什么:
object_id(N'dbo.MyTable')
回答by Joe Koberg
It indicates a "nationalized" a.k.a. unicode string constant.
它表示“国有化”又名 unicode 字符串常量。
http://support.microsoft.com/kb/239530
http://support.microsoft.com/kb/239530
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".
在 SQL Server 中处理 Unicode 字符串常量时,必须在所有 Unicode 字符串前面加上大写字母 N,如 SQL Server 联机丛书主题“使用 Unicode 数据”中所述。
http://msdn.microsoft.com/en-us/library/aa276823%28SQL.80%29.aspx
http://msdn.microsoft.com/en-us/library/aa276823%28SQL.80%29.aspx
nchar
andnvarchar
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)
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)
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.
nchar
和nvarchar
固定长度 (nchar) 或可变长度 (nvarchar) Unicode 数据并使用 UNICODE UCS-2 字符集的字符数据类型。
nchar(n)
n 个字符的固定长度 Unicode 字符数据。n 必须是 1 到 4,000 之间的值。存储大小是 n 字节的两倍。SQL-92 的同义词
nchar
是national char 和 national character。
nvarchar(n)
n 个字符的可变长度 Unicode 字符数据。n 必须是 1 到 4,000 之间的值。存储大小(以字节为单位)是输入字符数的两倍。输入的数据长度可以为 0 个字符。SQL-92 的同义词
nvarchar
是national char variables 和 national character changed。