Wednesday, March 7, 2012

quick easy question

Whats the difference between nvarchar and varchar, and which one should I use?
Thanksnvarchar is unicode (to support alternate charactersets), varchar is not.|||I looked at the help in SQL server and found that but didn't really understand, I don't plan to have any foreign Charecters in my database, but is there any reason not to use nvarchar just incase?|||from SQL Server Books Online...

char and varchar
Fixed-length (char) or variable-length (varchar) character data types.

nchar and nvarchar
Character data types that are either fixed-length (nchar) or variable-length (nvarchar) Unicode data and use the UNICODE UCS-2 character set.

If you need to store Unicode data use the nchar or nvarchar variation otherwise use char or varchar.|||Thanks for you help will use Varchar then, hope you all had a merry Christmas.|||I looked at the help in SQL server and found that but didn't really understand, I don't plan to have any foreign Charecters in my database, but is there any reason not to use nvarchar just incase?

You reduce your storage space by half...

with varchar(100) you can store 100 bytes of data with nvarchar(100) you can only store 50 bytes of data, the remaining space is used for unicode support.|||In BOL the topic "Character Data" , the topic "Using Unicode Data" says:

Use of nchar, nvarchar, and ntext is the same as char, varchar, and text, respectively, except that:

- Unicode supports a wider range of characters.
- More space is needed to store Unicode characters.
- The maximum size of nchar and nvarchar columns is 4,000 characters, not 8,000 characters like char and varchar.
- Unicode constants are specified with a leading N: N'A Unicode string'.

So I guess it really depends on what the column is used for. If there's no need to support alternate charactersets, I'd go for varchar.

No comments:

Post a Comment