I generated an sql script like this,
我生成了这样的sql脚本,
INSERT [dbo].[TableName] ([Sno], [Name], [EmployeeId], [ProjectId], [Experience])
VALUES (1, N'Dave', N'ESD157', N'FD080', 7)
I wonder whats that N' exactly mean and whats its purpose here.
我想知道那到底是什么意思,它的目的是什么。
NOTE: By searching for the answer all i can get is that N' is a prefix for National language standard and its for using unicode data. But honestly i am not able to get a clear idea about the exact operation of N' here. I'd appreciate your help and please make it in more of an understandable way. Thanks in advance.
注意:通过搜索答案,我只能得到N'是国家语言标准的前缀,它是用于使用unicode数据的前缀。但老实说,我不知道N'的确切运算。我很感激你的帮助,请用一种更容易理解的方式。提前谢谢。
6 个解决方案
#1
20
N
is used to specify a unicode string.
N用于指定unicode字符串。
Here's a good discussion http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an-n-prefix.html
这里有一个很好的讨论http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an- prefix.html
In your example N
prefix is not required because ASCII characters (with value less than 128) map directly to unicode. However, if you wanted to insert a name that was not ASCII then the N
prefix would be required.
在示例中不需要N前缀,因为ASCII字符(值小于128)直接映射到unicode。但是,如果您想插入一个非ASCII的名称,则需要N个前缀。
INSERT [dbo].[TableName] ([Sno], [Name], [EmployeeId], [ProjectId], [Experience])
VALUES (1, N'Wāhi', 'ESD157', 'FD080', 7)
#2
6
The "N"
prefix stands for National Language in the SQL-92 standard, and is used for representing unicode characters.
“N”前缀在SQL-92标准中表示国家语言,用于表示unicode字符。
Any time you pass Unicode data to SQL Server you must prefix the Unicode string with N
.
每当您将Unicode数据传递给SQL Server时,必须在Unicode字符串前面加上N。
It is used when the type is from NVARCHAR
, NCHAR
or NTEXT
.
当类型来自NVARCHAR、NCHAR或NTEXT时使用。
For more info refer to this: What’s up with the N in front of string values?
更多信息请参考以下内容:在字符串值前面的N是什么?
#3
4
'abcd'
is a literal for a [var]char
string (or maybe text
, but varchar(max)
would be more common now) - occupying 4 bytes memory, and using whatever code-page the SQL server is configured for. N'abcd'
is a literal for a n[var]char
string (or maybe ntext
, but nvarchar(max)
would be preferable), occupying 8 bytes of memory using UTF-16. This allows for full international usage, and frankly n[var]char
should probably be the default in most systems.
“abcd”是[var]字符字符串(或者可能是文本,但varchar(max)现在更常见)的一个文本——占用4字节内存,并使用SQL服务器配置的任何代码页。N'abcd'是一个N [var]字符字符串的文本(或者可能是ntext,但最好是nvarchar(max))),使用UTF-16占用8字节的内存。这允许充分的国际使用,而且坦率地说,n[var]字符在大多数系统中可能是默认的。
#4
2
This denotes that the subsequent string is in Unicode
(the N actually stands for National language character set).
这表示后面的字符串是Unicode (N实际上代表国家语言字符集)。
Which means that you are passing an NCHAR
, NVARCHAR
or NTEXT
value, as opposed to CHAR
, VARCHAR
or TEXT
.
这意味着您正在传递一个NCHAR、NVARCHAR或NTEXT值,而不是CHAR、VARCHAR或TEXT。
- SOURCE
- 源
#5
1
N is to specify that its a string type value.
N是指定它是一个字符串类型值。
[N]“tsql_string”
Is a constant string. tsql_string can be any nvarchar or varchar data type. If the N is included, the string is interpreted as nvarchar data type.
是一个常量字符串。tsql_string可以是任何nvarchar或varchar数据类型。如果包含N,则将字符串解释为nvarchar数据类型。
#6
0
each country has its own specific letters and symbols so a database set up for English US will not recognise the £ symbol which a English UK database would, the same goes for Spanish, French, German
每个国家都有自己的特定的字母和符号数据库设置英语我们不会认识到£象征英国英文数据库,这同样适用于西班牙语,法语,德语
Also other languages like Chinese, Japanese, Hebrew, Arabic don't use any Latin characters.
其他语言如汉语、日语、希伯来语、阿拉伯语也不使用任何拉丁字符。
so anyone trying to enter any data not contained in the local character set will fail or suffer data corruption, if you are using varchar, so if there is even the remotest possibility that your database will need to support more than one local character set then you have to use the nationalised language character set aka unicode aka NChar, which allows the character sets nationality to be recorded with the character. providing international text support
所以有人试图进入任何数据不包含在本地字符集将失败或受数据损坏,如果您正在使用varchar,所以如果还有最偏远的可能性数据库将需要支持多个本地字符集那么必须使用unicode字符集即国有化语言即NChar,它允许的字符集国籍与这个角色被记录。提供国际文本支持
Likewise adding the N Prefix to a string instructs the database to include the Nation code as well as the character code
同样,在字符串中添加N前缀将指示数据库包含国家代码和字符代码
#1
20
N
is used to specify a unicode string.
N用于指定unicode字符串。
Here's a good discussion http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an-n-prefix.html
这里有一个很好的讨论http://databases.aspfaq.com/general/why-do-some-sql-strings-have-an- prefix.html
In your example N
prefix is not required because ASCII characters (with value less than 128) map directly to unicode. However, if you wanted to insert a name that was not ASCII then the N
prefix would be required.
在示例中不需要N前缀,因为ASCII字符(值小于128)直接映射到unicode。但是,如果您想插入一个非ASCII的名称,则需要N个前缀。
INSERT [dbo].[TableName] ([Sno], [Name], [EmployeeId], [ProjectId], [Experience])
VALUES (1, N'Wāhi', 'ESD157', 'FD080', 7)
#2
6
The "N"
prefix stands for National Language in the SQL-92 standard, and is used for representing unicode characters.
“N”前缀在SQL-92标准中表示国家语言,用于表示unicode字符。
Any time you pass Unicode data to SQL Server you must prefix the Unicode string with N
.
每当您将Unicode数据传递给SQL Server时,必须在Unicode字符串前面加上N。
It is used when the type is from NVARCHAR
, NCHAR
or NTEXT
.
当类型来自NVARCHAR、NCHAR或NTEXT时使用。
For more info refer to this: What’s up with the N in front of string values?
更多信息请参考以下内容:在字符串值前面的N是什么?
#3
4
'abcd'
is a literal for a [var]char
string (or maybe text
, but varchar(max)
would be more common now) - occupying 4 bytes memory, and using whatever code-page the SQL server is configured for. N'abcd'
is a literal for a n[var]char
string (or maybe ntext
, but nvarchar(max)
would be preferable), occupying 8 bytes of memory using UTF-16. This allows for full international usage, and frankly n[var]char
should probably be the default in most systems.
“abcd”是[var]字符字符串(或者可能是文本,但varchar(max)现在更常见)的一个文本——占用4字节内存,并使用SQL服务器配置的任何代码页。N'abcd'是一个N [var]字符字符串的文本(或者可能是ntext,但最好是nvarchar(max))),使用UTF-16占用8字节的内存。这允许充分的国际使用,而且坦率地说,n[var]字符在大多数系统中可能是默认的。
#4
2
This denotes that the subsequent string is in Unicode
(the N actually stands for National language character set).
这表示后面的字符串是Unicode (N实际上代表国家语言字符集)。
Which means that you are passing an NCHAR
, NVARCHAR
or NTEXT
value, as opposed to CHAR
, VARCHAR
or TEXT
.
这意味着您正在传递一个NCHAR、NVARCHAR或NTEXT值,而不是CHAR、VARCHAR或TEXT。
- SOURCE
- 源
#5
1
N is to specify that its a string type value.
N是指定它是一个字符串类型值。
[N]“tsql_string”
Is a constant string. tsql_string can be any nvarchar or varchar data type. If the N is included, the string is interpreted as nvarchar data type.
是一个常量字符串。tsql_string可以是任何nvarchar或varchar数据类型。如果包含N,则将字符串解释为nvarchar数据类型。
#6
0
each country has its own specific letters and symbols so a database set up for English US will not recognise the £ symbol which a English UK database would, the same goes for Spanish, French, German
每个国家都有自己的特定的字母和符号数据库设置英语我们不会认识到£象征英国英文数据库,这同样适用于西班牙语,法语,德语
Also other languages like Chinese, Japanese, Hebrew, Arabic don't use any Latin characters.
其他语言如汉语、日语、希伯来语、阿拉伯语也不使用任何拉丁字符。
so anyone trying to enter any data not contained in the local character set will fail or suffer data corruption, if you are using varchar, so if there is even the remotest possibility that your database will need to support more than one local character set then you have to use the nationalised language character set aka unicode aka NChar, which allows the character sets nationality to be recorded with the character. providing international text support
所以有人试图进入任何数据不包含在本地字符集将失败或受数据损坏,如果您正在使用varchar,所以如果还有最偏远的可能性数据库将需要支持多个本地字符集那么必须使用unicode字符集即国有化语言即NChar,它允许的字符集国籍与这个角色被记录。提供国际文本支持
Likewise adding the N Prefix to a string instructs the database to include the Nation code as well as the character code
同样,在字符串中添加N前缀将指示数据库包含国家代码和字符代码