silent200
silent200

Reputation:

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

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.

Upvotes: 11

Views: 18201

Answers (4)

kroiz
kroiz

Reputation: 1772

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

Upvotes: 0

Scott Ivey
Scott Ivey

Reputation: 41558

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."

Upvotes: 3

devio
devio

Reputation: 37215

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.

Upvotes: 13

Vincent
Vincent

Reputation: 22944

It is preferable for compatibility sake.

Upvotes: 0

Related Questions