Board index » delphi » MS SQL 6.5 VarChar vs Char

MS SQL 6.5 VarChar vs Char

G'Day All,

What are the benefits / drawbacks in using VarChar as opposed to Char
for table field definitions in terms of perfomance and storage???

TIA

--Donovan
PS - Please CC me if possible
--Donovan

---------------------------------------------------------------------------
E-Mail: dono...@junkmail.co.za

"Very funny Scottie! Now beam down my pants!!!"
Junk Mail South Africa
http://www.junkmail.co.za
---------------------------------------------------------------------------

 

Re:MS SQL 6.5 VarChar vs Char


Donovan,
As I understand it the Char type is very much like the old pascal String
type. It is intended for string data that does not vary greatly in size from
one row to the next. I believe the Varchar type works differently from the
Char type in how it setups memory. If you declare a Char(30), then 30 bytes
of space is used for each row. If you put a small string in the Char(30)
field {"TEST" for example}, the first 4 bytes will contain the characters of
the string, and the remaining 26 characters of the field will be filled with
spaces.

Now if you declare the same field as Varchar(30) and set one of the rows
equal to a small string such as "TEST", only the four characters of the
string are stored. But these four characters are not stored in the same
place as the rest of the row. The Varchar field is really a pointer into
another area( I'm guessing a special set of memory pages) where the varchar
string data is held. All of this is going to require some overhead. I
believe that managing all this dynamic string data is going to take time. I
don't know for sure, but I think that Varchar's may be slower than a regular
Char type. The advantage is that Varchars use storage space much more
efficiently. I'm not sure, but I think that if your rows have strings that
vary a lot in size (maybe the go from 2 characters to 128), you may be able
to save a lot of disk space by using a Varchar field.

I'm not sure if I covered all the differences of Chars and Varchars, but I
hope this helps.

Dwight Fowler
rads...@swbell.net

Other Threads