問題描述
我正在查看的代碼是這樣的:
The code I am looking at is this:
SET @Message = N'Question result is ''' + @CurrentResult + '''. It should be unmarked or incorrect';
THROW 50002,@Message,1
誰能解釋一下為什么開發(fā)人員在引號(hào)前加了N"?
Can someone explain why the developer but "N" before the quotes?
推薦答案
來自 MSDN在備注部分
說字符串是 Nvarchar
類型并且可以有 unicode 字符
Saying that string is of Nvarchar
type and can have unicode charcters
用字母 N 前綴 Unicode 字符串常量.沒有N 前綴,字符串被轉(zhuǎn)換為默認(rèn)代碼頁數(shù)據(jù)庫.此默認(rèn)代碼頁可能無法識(shí)別某些字符.
Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.
"N"
前綴代表 SQL-92 標(biāo)準(zhǔn)中的國家語言,必須大寫.如果不使用 N 作為 Unicode 字符串常量的前綴,SQL Server 會(huì)在使用該字符串之前將其轉(zhuǎn)換為當(dāng)前數(shù)據(jù)庫的非 Unicode 代碼頁.
The "N"
prefix stands for National Language in the SQL-92 standard, and must be uppercase. If you do not prefix a Unicode string constant with N, SQL Server will convert it to the non-Unicode code page of the current database before it uses the string.
這里有更詳細(xì)的信息
在處理 Unicode 字符串常量時(shí),必須在所有 Unicode 字符串前加上前綴 NSQL Server
這篇關(guān)于“N"是什么意思?在 SQL Server 分配中的引號(hào)之前?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!