Do I have use the prefix N in the “insert into” statement for unicode?

后端 未结 4 2139
不知归路
不知归路 2020-12-14 22:15

Like:
insert into table (col) values (N\'multilingual unicode strings\')

I\'m using SQL Server 2008 and I already use nVarChar as the column data type.

相关标签:
4条回答
  • 2020-12-14 22:52

    Yes, you do if you have unicode characters in the strings.

    From books online (http://msdn.microsoft.com/en-us/library/ms191313.aspx)...

    "Unicode string constants that appear in code executed on the server, such as in stored procedures and triggers, must be preceded by the capital letter N. This is true even if the column being referenced is already defined as Unicode. Without the N prefix, the string is converted to the default code page of the database. This may not recognize certain characters. The requirement to use the N prefix applies to both string constants that originate on the server and those sent from the client."

    0 讨论(0)
  • 2020-12-14 22:54

    You need the N'' syntax only if the string contains characters which are not inside the default code page. "Best practice" is to have N'' whenever you insert into an nvarchar or ntext column.

    0 讨论(0)
  • 2020-12-14 22:55

    It is preferable for compatibility sake.

    0 讨论(0)
  • 2020-12-14 23:03

    Best practice is to use parameterisation in which case you don't need the N prefix.

    0 讨论(0)
提交回复
热议问题