I am storing first name and last name with up to 30 characters each. Which is better varchar
or nvarchar
.
I have read that nvarchar
First of all, to clarify, nvarchar
stores unicode data while varchar
stores ANSI (8-bit) data. They function identically but nvarchar takes up twice as much space.
Generally, I prefer storing user names using varchar
datatypes unless those names have characters which fall out of the boundary of characters which varchar
can store.
It also depends on database collation also. For e.g. you'll not be able to store Russian characters in a varchar
field, if your database collation is LATIN_CS_AS
. But, if you are working on a local application, which will be used only in Russia, you'd set the database collation to Russian. What this will do is that it will allow you to enter Russian characters in a varchar
field, saving some space.
But, now-a-days, most of the applications being developed are international, so you'd yourself have to decide which all users will be signing up, and based on that decide the datatype.