What is the meaning of the prefix N in T-SQL statements and when should I use it?

前端 未结 4 736
长情又很酷
长情又很酷 2020-11-22 01:01

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

I searched, but I was not able to unde

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 01:13

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

    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.

    To quote from Microsoft:

    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.


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

    What is the difference between varchar and nvarchar?

提交回复
热议问题