T-SQL 语句中前缀 N 的含义是什么,我应该什么时候使用它? [英] What is the meaning of the prefix N in T-SQL statements and when should I use it?

查看:25
本文介绍了T-SQL 语句中前缀 N 的含义是什么,我应该什么时候使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些插入 T-SQL 查询中看到过前缀 N.许多人在将值插入表中之前使用了 N.

I have seen prefix N in some insert T-SQL queries. Many people have used N before inserting the value in a table.

我进行了搜索,但在向表中插入任何字符串之前,我无法理解包含 N 的目的是什么.

I searched, but I was not able to understand what is the purpose of including the N before inserting any strings into the table.

INSERT INTO Personnel.Employees
VALUES(N'29730', N'Philippe', N'Horsford', 20.05, 1),

这个N"前缀的用途是什么,应该在什么时候使用?

What purpose does this 'N' prefix serve, and when should it be used?

推荐答案

它将字符串声明为 nvarchar 数据类型,而不是 varchar

It's declaring the string as nvarchar data type, rather than varchar

您可能已经看到 Transact-SQL 代码使用以下方式传递字符串一个 N 前缀.这表示后续字符串是 Unicode(N 实际上代表国家语言字符集).哪一个表示您正在传递 NCHAR、NVARCHAR 或 NTEXT 值,如与 CHAR、VARCHAR 或 TEXT 相对.

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.

引用来自微软:

用字母 N 前缀 Unicode 字符串常量.没有N 前缀,字符串被转换为默认代码页数据库.此默认代码页可能无法识别某些字符.

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.


如果您想知道这两种数据类型之间的区别,请参阅此 SO 帖子:


If you want to know the difference between these two data types, see this SO post:

varchar 和 nvarchar 有什么区别?

这篇关于T-SQL 语句中前缀 N 的含义是什么,我应该什么时候使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆