I wonder about the difference between different data types in SQL Server to store strings.
For example ntext
, nvarchar(X)
, varchar
, nvarchar(max)
etc.
What could be the advices in terms of flexibility, resource usage and performance?
I wonder about the difference between different data types in SQL Server to store strings.
For example ntext
, nvarchar(X)
, varchar
, nvarchar(max)
etc.
What could be the advices in terms of flexibility, resource usage and performance?
All the string types the N
are unicode - 2 bytes for each characters, will store things like Cyrillic, Asian, Arabic, Hebrew alphabets - while those without the leading N
are not unicode (only properly store Western European / ASCII characters)
TEXT
and NTEXT
are deprecated - don't use those anymore - use (N)VARCHAR(MAX)
instead - see the relevant MSDN documentation on that topic for details
NVARCHAR(X)
is a "normal" string, max. of 8000 bytes of data (4000 Unicode or 8000 non-Unicode characters) - stored in the regular page in SQL Server
NVARCHAR(MAX)
is a special type, up to 2 GB of storage (1 billion Unicode characters) - but it requires special handling in storage, more effort needed, performs a bit slower than regular strings; use only when absolutely needed
refer to the link below for difference between nvarchar and varchar then choose the best for you
For normal english letters use the varchar and for any other languages and foreign characters use nvarchar. varchar uses 1 byte per charcater to store and nvarchar uses 2bytes per character.