What is meant by nvarchar
?
What is the difference between char
, nchar
, varchar
, and nvarchar
in SQL Server?
When to use what? If your column will store a fixed-length Unicode characters like French, Arabic and so on characters then go for NCHAR. If the data stored in a column is Unicode and can vary in length, then go for NVARCHAR.
The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.
The NCHAR data type is a fixed-length character data type that supports localized collation. The NVARCHAR data type is a varying-length character data type that can store up to 255 bytes of text data and supports localized collation.
What's the difference between CHAR and VARCHAR? The short answer is: VARCHAR is variable length, while CHAR is fixed length. CHAR is a fixed length string data type, so any remaining space in the field is padded with blanks. CHAR takes up 1 byte per character.
Just to clear up... or sum up...
nchar
and nvarchar
can store Unicode characters.char
and varchar
cannot store Unicode characters.char
and nchar
are fixed-length which will reserve storage space for number of characters you specify even if you don't use up all that space.varchar
and nvarchar
are variable-length which will only use up spaces for the characters you store. It will not reserve storage like char
or nchar
.nchar
and nvarchar
will take up twice as much storage space, so it may be wise to use them only if you need Unicode support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With