SQL where 子句中的“N" [英] The 'N' in the where clause of SQL
问题描述
我在某处看到了这个查询 -
I saw this query somewhere -
SELECT *
FROM HR.Employees
WHERE country <> N'JAP';
那个 N" 是什么意思?我不确定这是否仅对 SQL 服务器有效.
What does that "N" mean ? I am not sure if this is valid only for SQL server.
推荐答案
N 代表National Character",表示字符串的内容是 Unicode.
The N stands for "National Character" and it means that the content of the string is Unicode.
每当您遇到可能包含默认 ASCII 字符集之外的字符的专有名称或其他实体时,您都应该使用 Unicode (nchar
/nvarchar
).如果您不使用 N
前缀将此类字符串括起来,您将丢失数据.例如:
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'ук ферт хер', 'ук ферт хер';
结果:
----------- -----------
ук ферт хер ?? ???? ???
您还应该确保在 WHERE
或其他针对 n(var)char
列的子句中使用 N
前缀.当您不使用 N
前缀时,您可能会因隐式转换而遭受严重的性能问题.
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.
这篇关于SQL where 子句中的“N"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!