Why the prefix N is used for literal strings in Sql Server?

The Prefix N conveys to the Sql Server that following literal string is of Unicode type. While storing Unicode (i.e. Japanese, Korean, Chinese etc) Characters in NChar, NVarchar or NText columns or variables we need to prefix the literal strings by letter N.

Below examples demonstrates the importance of the Prefix N for Unicode Characters in Sql Server and the issues which we may face if it is not used where it is required.

Double byte Characters are Stored/displayed as questions Marks if the Prefix N is not used
Example 1:

SELECT '名前' AS 'Double byte Characters without Prefix N'
GO
SELECT N'名前' AS 'Double byte Characters with Prefix N'

Double Byte Characters are displayed as Question Marks

One thought on “Why the prefix N is used for literal strings in Sql Server?

Leave a Reply

Your email address will not be published. Required fields are marked *