char, varchar and nvarchar are SQL Server data type that used for allocated memory in storage device. But there is little difference between them which described below:
char
It stores fixed length of character. For example if you declare char (10) then it allocates memory for 10 characters. If you store 5 character words then it stores it in 5 characters memory location and other 5 character's memory location will be wasted. Per character, it takes 1 Byte memory.
varchar
varchar is flexible data type means it allocates memory as per data stored into this. If you specify varchar(10) at the time of declaration then it allocates 0 memory location at the starting if you specify, it can be null. When you store 5 characters word it will allocate memory for 5 characters and store into that. So there will be no memory loss. It stores only non-unicode characters means for English language only. Per character, it takes 1 Bytes memory.
nvarchar
nvarchar means unicode variable characters. When you want to store international character in database then used nvarhcar. It used really because it increases database size twice than varchar datatype because it takes 2 Bytes memory for each character.
Leave Comment