Groups | Blog | Home
all groups > sql server (microsoft) > december 2005 >

sql server (microsoft) : SQL Server, setting Char,VarChar lengths... (very basic question :)



W.Sh
12/27/2005 10:46:48 AM
Hi Everyone!

I'm relatively new to MS SQL Server, and I have a pretty basic
question, which I want to make sure I understand correctly.

When I'm designing a table in Enterprise Manager, I use Char and
VarChar data types. As I understand you should set their length to the
smallest size possible needed to accomplish your tasks, so to optimize
performance. Now, when I set the data type to Char, the Length appears
by default as 16, and with VarChar it's 50.

Do these numbers represent the actual number of charachters allowed, or
do they represent the length in bytes?

i.e when I set the the length to 3 for example, does this mean:
1. I can insert 3 charachters into the field, for example: "abc"
2. or, does this mean 3 bytes, in which case 1 byte = 8 bits, thus 3x8
= 24 chars
"abcdefghijklmnopqrstuvqx" ?

Thanks! :)
RCS
12/27/2005 8:24:16 PM
It means the actual number of characters that can be stored...

[quoted text, click to view]

Phil
1/3/2006 4:29:44 AM
It means both characters and bytes, but the number of bytes is
equivalent to the number of characters (1 character per byte).

Computer systems generally (not just databases) usually refer to
individual characters and symbols by a unique number (the ASCII value,
although there are other schemes). Letter 'A', for example, has an
ASCII value of 65. In binary code it is possible to represent up to
255 individual numbers (i.e. characters) using 8 bits or 1 byte. Thus,
it requires 1 byte to store each character.
AddThis Social Bookmark Button