Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 char, varchar, nchar or nvarchar

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-07-27 : 18:19:26
Hello,

When should I use char, varchar, nchar or nvarchar?

For example, on the following table I am using it as follows:

create table Assets
(
ID uniqueidentifier not null
constraint PK_Asset primary key clustered,
Content nvarchar(max) null,
Created datetime null,
Locked bit null,
[Name] nchar(100) null,
Priority tinyint null,
Type nchar(40) null,
Updated datetime null
) -- Assets

Thanks,
Miguel

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-27 : 18:22:49
How often will Name and Type be near 100 respectively 40 characters?
If Name and Type are much smaller, in general, a NVARCHAR datatype will take smaller space in your table despite of the VAR overhead.
You also have to remember than CHAR datatype pads trailing spaces to the names and types so that they will be 100 and 40 characters long. Doing this LEN() and DATALENGTH() will yield different results.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-27 : 20:14:46
additionally, if you're never going to support non-latin languages, should use varchar/char instead of nvarchar/nchar
Go to Top of Page
   

- Advertisement -