Is it just that nvarchar
supports multibyte characters? If that is the case, is there really any point, other than storage concerns, to using varchars
The main difference between Varchar(n)
and nvarchar(n)
is:
Varchar
( Variable-length, non-Unicode character data) size is upto 8000.
1.It is a variable length data type
Used to store non-Unicode characters
Occupies 1 byte of space for each character
Nvarchar
:Variable-length Unicode character data.
1.It is a variable-length data type
2.Used to store Unicode characters.
Follow Difference Between Sql Server VARCHAR and NVARCHAR Data Type. Here you could see in a very descriptive way.
In generalnvarchar stores data as Unicode, so, if you're going to store multilingual data (more than one language) in a data column you need the N variant.
nvarchar
is safe to use compared to varchar
in order to make our code error free (type mismatching) because nvarchar
allows unicode characters also.
When we use where
condition in SQL Server query and if we are using =
operator, it will throw error some times. Probable reason for this is our mapping column will be difined in varchar
. If we defined it in nvarchar
this problem my not happen. Still we stick to varchar
and avoid this issue we better use LIKE
key word rather than =
.
You're right. nvarchar
stores Unicode data while varchar
stores single-byte character data. Other than storage differences (nvarchar
requires twice the storage space as varchar
), which you already mentioned, the main reason for preferring nvarchar
over varchar
would be internationalization (i.e. storing strings in other languages).
I always use nvarchar as it allows whatever I'm building to withstand pretty much any data I throw at it. My CMS system does Chinese by accident, because I used nvarchar. These days, any new applications shouldn't really be concerned with the amount of space required.
nvarchar stores data as Unicode, so, if you're going to store multilingual data (more than one language) in a data column you need the N variant.