What is the purpose of putting an 'N' in front of function parameters in TSQL?
For example, what does the N
mean in front of the function parameter in the following code:
object_id(N'dbo.MyTable')
"You may have seen Transact-SQL code that passes strings around using an N prefix. This denotes that the subsequent string is in Unicode (the N actually stands for National language character set). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT.
The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters. In the current standard, it must be an upper case , which is what you will typically find implemented in mainstream products.
n or N refers to Unicode... It means that the text in the variable uses Unicode. It also means that the size of the variable is 2 bytes per character instead of 1 byte per char like a varchar() variable would be.
The N just tells the parser that the string literal should be or is a double-byte (unicode) string. Since your parameter is already of type NVARCHAR the parser knows that what it is.
It indicates a "nationalized" a.k.a. unicode string constant.
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".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With