Char / Varchar / Nvarchar datatype in SQL Server


Char data type:
 
 
    It is a fixed length data type and allows character datatype.
 
For instance, if you have char(5) then it occupies fixed length of 5 bytes even though you have a string which have less than 5 character's length. The rest of the character are treated as blank spaces.
 
 
Varchar datatype:
 
     It is a variable length data type and it occupies length for each row dynamically.  So it doesn't have fixed length. In most of the cases, varchar type is preferred due to its proper memory usage. It occupies 1 bytes for each character. varchar (max) will have the max of 8000 in lower versions and 2 GB is upper versions.
 
 
Nvarchar data type :
 
     To support different language beyond English language, Nvarchar data type is used.
Basically, it supports unicode characters. It has the base property of varchar with memory of 2 bytes for each character. nvarchar (max) will have the max of 4000 in lower versions and 2 GB is upper versions.
 
Cheers,
Ebook Download
View all
Learn
View all