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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 05:41:18  来源:igfitidea点击:

What is the purpose of putting an 'N' in front of function parameters in TSQL?

sqlsql-servertsql

提问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 Nmean 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

ncharand nvarchar

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 ncharare 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 nvarcharare national char varying and national character varying.

ncharnvarchar

固定长度 (nchar) 或可变长度 (nvarchar) Unicode 数据并使用 UNICODE UCS-2 字符集的字符数据类型。

nchar(n)

n 个字符的固定长度 Unicode 字符数据。n 必须是 1 到 4,000 之间的值。存储大小是 n 字节的两倍。SQL-92 的同义词ncharnational char 和 national character

nvarchar(n)

n 个字符的可变长度 Unicode 字符数据。n 必须是 1 到 4,000 之间的值。存储大小(以字节为单位)是输入字符数的两倍。输入的数据长度可以为 0 个字符。SQL-92 的同义词nvarcharnational char variables 和 national character changed