Groups | Blog | Home
all groups > sql server new users > february 2005 >

sql server new users : Default data type


Sam
2/24/2005 1:47:02 AM
Fundamental question this but is there any set law when choosing the right
data type as applied to characters. I have a list of names which I’ve
imported into sql 2000 from an excel file. It defaults to 255 nchar is this
correct? Should I leave it?
Many thanks
Sam
Walter Clayton
2/24/2005 10:32:23 AM
[quoted text, click to view]

Law? No. You define and control the charastics as dictated by the business
needs.

[quoted text, click to view]

That's normal.

[quoted text, click to view]

Your call. That data type is fixed length 255 unicode. If that fits your
needs and you're not concerned about the size of the column, then let it
rip.

[quoted text, click to view]


--
Walter Clayton
Any technology distinguishable from magic is insufficiently advanced.
http://www.dts-l.org


Adam Machanic
2/24/2005 11:15:14 AM
NCHAR is for Unicode characters and uses two bytes per character such that
it can accommodate non-latin character sets; if you're only storing
characters from latin (English/Spanish/French/etc) languages, using CHAR or
VARCHAR will be more efficient. You don't need the extra byte.

As for CHAR vs. VARCHAR, I almost always use the latter. The former
right-pads any characters you put in. So if you have, e.g. a CHAR(10)
column and store the value 'ABC', what's really stored by the database
engine is 'ABC ' -- You're storing 10 bytes of data every time.
VARCHAR, on the other hand, trims spaces from the right of the string, at
the expense of an extra byte to store the string's length. So the string
'ABC' in a VARCHAR(10) column will take up 4 bytes. A six-byte savings over
CHAR, plus you don't have to worry about trimming the spaces when you
retrieve the data. Much, much nicer, in my opinion.

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


[quoted text, click to view]

AddThis Social Bookmark Button