Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does nvarchar always take twice as much space as varchar?

Tags:

sql

database

Nvarchar is used to store unicode data which is used to store multilingual data. If you don't end up storing unicode does it still take up the same space?

like image 682
The Muffin Man Avatar asked Jan 21 '11 03:01

The Muffin Man


2 Answers

YES.

See MSDN Books Online on NCHAR and NVARCHAR.

NCHAR:

The storage size is two times n bytes.

NVARCHAR

The storage size, in bytes, is two times the number of characters entered + 2 bytes

like image 191
marc_s Avatar answered Sep 21 '22 03:09

marc_s


Sort of. Not all unicode characters use two bytes. Utf-8, for example, is still just one byte per character a lot of the time, but rarely you may need 4 bytes per character. What nvarchar will do is allocate two bytes per character.

like image 28
Joel Coehoorn Avatar answered Sep 20 '22 03:09

Joel Coehoorn