Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

nchar(10) vs nvarchar(50)

Can someone explain in laymens terms what is the difference between these two data types?

nchar(10) vs nvarchar(50)
ASKER CERTIFIED SOLUTION
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cyberkiwi left nothing for us to grab some points ;)
Avatar of al4629740

ASKER

So does nchar(10) pose some problems when trying to query data vs. nvarchar(50)
i never use nchar(x), use nvarchar(x) all the time, if necessary use sql functions to pad it to desired level
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it will be tricky to write your queries with nchar(x)
you may need to use RTrim(column) all the time....
> So does nchar(10) pose some problems when trying to query data vs. nvarchar(50)

It may, due to the trailing spaces.  If you have a nchar(10) column and you store "Bob" into it, and you add it to a firstname, like Col1 + ", Jones", you won't get "Bob, Jones", you get "Bob       , Jones".


HainKurt FYI,

http://msdn.microsoft.com/en-us/library/ms186939.aspx

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

If the customer code is always going to be 10 characters, nchar(10) will save you 2 bytes per row compared to nvarchar(10).

Having it as VAR(ying) length requires 2 additional bytes to store the actual length of data.