Wednesday, November 07, 2012

Difference between Varchar and Nvarchar

As we all know the basic difference between varchar and Nvarchar is that one holds non Unicode and other holds Unicode data. But we are just aware theoretically and don’t know how it works actually.
Here I am showing an example of how varchar and nvarchar data types works in query analyzer
Declare @sampleVar varchar(10)
Declare @sampleNVar nvarchar(10)
set @sampleVar = 'VarSamp Ж'
set @sampleNVar = 'NVarSamp Ж'

Select @sampleNVar, @sampleVar

set @sampleNVar = N'NVarSamp Ж'
set @sampleVar = N'VarSamp Ж'

Select @sampleNVar, @sampleVar
If you will see we have added the suffix N while setting the Unicode data type and its display’s the results otherwise it show’s the same result as varchar data type. By seeing this example we can say in Unicode data types can be handled through nvarchar so while developing bilingual application or if there is any possibility to use current application in different languages we should use Nvarchar data types.

Keywords: How to read nvarchar data in SQL Query Analyzer, SQL Server Data types, SQL Server Questions, Varchar ,Nvarchar.

1 comment: