Table of Differences

 charncharvarcharnvarchar
Character Data Type
ASCII
UnicodeASCIIUnicode
Maximum Lengthup to 8,000 charactersup to 4,000 charactersup to 8,000 charactersup to 4,000 characters
Character Sizetakes up 1 byte per charactertakes up 2 bytes per Unicode/Non-Unicode charactertakes up 1 byte per charactertakes up 2 bytes per Unicode/Non-Unicode character
Storage Sizen bytes2 times n bytesActual Length (in bytes)2 times Actual Length (in bytes)
Usageuse when data length is constant or fixed length columnsuse only if you need Unicode support such as the Japanese Kanji or Korean Hangul characters due to storage overheadused when data length is variable or variable length columns and if actual data is always way less than capacityuse only if you need Unicode support such as the Japanese Kanji or Korean Hangul characters due to storage overhead

Query that uses a varchar parameter does an index seek due to column collation sets.
Query that uses a nvarchar parameter does an index scan due to column collation sets.

Advantages and Disadvantages

Data TypesAdvantagesDisadvantages
charQuery performance is better since no need to move the column while updating.No need to store the length of string in last two bytes.If not properly used, it can take more space than varchar since it is fixed length and we don’t know the length of string to be stored.It is not good for compression since it embeds space characters at the end.
varcharSince it is variable length it takes less memory spaces.Decreases the performance of some SQL queries.
nchar/nvarcharSupports many client computers that are running different locales.If not properly used it may use up a lot of extra storage space.

Sources:

https://www.mssqltips.com/sqlservertip/4322/sql-server-differences-of-char-nchar-varchar-and-nvarchar-data-types/

Last modified: March 16, 2019

Author

Comments

Write a Reply or Comment