Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

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

I searched, but I can't 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),

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

1 Answer

0 votes
by (12.7k points)
edited by

It's simply 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.

Difference:

varchar: Variable-length, non-Unicode character data. The database collation decides which code page the data is stored using.

nvarchar: Variable-length Unicode character data. It depends on the database collation for comparisons. 

Want to be a SQL expert? Come and join this SQL server training and certification by Intellipaat.

If you are a beginner and want to know more about SQL, then do refer to the below SQL tutorial video that will help you out in a better way:

Related questions

+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...