I saw this query somewhere -
SELECT *
FROM HR.Employees
WHERE country <> N'JAP';
What does that "N" mean ? I am not sure if this is valid only for SQL server.
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 defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying.
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
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 stands for "National Character" and it means that the content of the string is Unicode.
You should be using Unicode (nchar
/nvarchar
) whenever you might come across proper names or other entities that can contain characters outside of the default ASCII character set. If you don't surround such strings with the N
prefix, you will lose data. For example:
SELECT N'ук ферт хер', 'ук ферт хер';
Results:
----------- -----------
ук ферт хер ?? ???? ???
You should also be sure to use the N
prefix in your WHERE
or other clauses against n(var)char
columns. When you don't use the N
prefix, you could suffer serious performance issues due to implicit conversion.
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