Pages

Thursday, 16 August 2012

Difference Between Sql Server VARCHAR and NVARCHAR Data Type


Difference Between Sql Server VARCHAR and NVARCHAR Data Type





The abbreviation for Varchar is non-Unicode Variable Length character String.

* The abbreviation of NVarchar is Unicode Variable Length character String. 

Differences :

Character Data Type
Varchar - Non-Unicode Data 
NVarchar - Unicode Data

2 Character Size 
Varchar - 1 byte
NVarchar - 2 bytes

3 Maximum Length 
Varchar - 8,000 bytes
NVarchar - 4,000 bytes

4 Storage Size 
Varchar - Actual Length (in bytes)
NVarchar - 2 times Actual Length (in bytes)



Difference between Sql Server Char and Varchar Data Type


Difference between Sql Server Char and Varchar Data Type



CHAR Data Type is a Fixed Length Data Type.
 For example if you declare a variable/column of CHAR (10) data type, then it will always take 10 bytes irrespective of whether you are storing 1 character or 10 character in this variable or column. And in this example as we have declared this variable/column as CHAR(10), so we can store max 10 characters in this column.

On the other hand VARCHAR is a variable length Data Type.
 For example if you declare a variable/column of VARCHAR (10) data type, it will take the no. of bytes equal to the number of characters stored in this column. So, in this variable/column if you are storing only one character then it will take only one byte and if we are storing 10 characters then it will take 10 bytes. And in this example as we have declared this variable/column as VARCHAR (10), so we can store max 10 characters in this column.