Search code examples
sql-serverunicodedata-migration

Avoiding code change with Microsoft SQLServer and Unicode


How can you get MSSQL server to accept Unicode data by default into a VARCHAR or NVARCHAR column?

I know that you can do it by placing a N in front of the string to be placed in the field but to by quite honest this seems a bit archaic in 2008 and particuarily with using SQL Server 2005.


Solution

  • The N syntax is how you specify a unicode string literal in SQL Server.

    N'Unicode string'
    'ANSI string'
    

    SQL Server will auto convert between the two when possible, using either a column's collation or the database's collation.

    So if your string literals don't actually contain unicode characters, you do not need to specify the N prefix.

    But if your string literals do contain unicode characters then using the N prefix is necessary.