Re: why use CHAR.. _EVER_?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I just don't see the point in having 20 fields that are all varchar(50)
when they only hold data that is 10 characters long.

stuff like keys?

i personally think that all keys everywhere should always be an
integer-- or preferably smallint--


it just drives me crazy; i've noted some definite peculiarities


like i've got field1 = 'aaron ' stored in a table; if i search
using a query where field1 = 'aaron' it finds a match; is this
implicit?

does it automatically do a right trim on everything you do in a char
field?

i just dont understand why 'aaron' matches to 'aaron '

it just seems inconsistent the way that they do it.

-Aaron




Russ Rose wrote:
<dbahooker@xxxxxxxxxxx> wrote in message
news:1159570979.959302.321990@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
can someone list some good reasons for using CHAR?

i mean seriously here.
I've got this 3rd party database that's got EVERY SINGLE TEXT FIELD
uses CHAR instead of VarChar.

it's slow as a dog..

does anyone know why ANYONE EVER USERS CHAR?


The funniest thing I have ever seen in a database design is a bunch of
varchar(1) columns...

When a column is a fixed width it is easier for a seek algorithm to find the
data within a row, which is why is is best to have variable length columns
at the end of the table.

Fixed length columns are best for data that will hold a required value of a
specific length. The best example of this is ZIPCode (not postal code) where
it is always 5 characters and you want to preserve any leading 0's.

I doubt the difference between char and varchar is the reason for your
performance issue.

.



Relevant Pages

  • Re: why use CHAR.. _EVER_?
    ... when they only hold data that is 10 characters long. ... stuff like keys? ... using a query where field1 = 'aaron' it finds a match; ... SQL, by definition, ignores white-space at the end of CHAR data types. ...
    (microsoft.public.sqlserver)
  • Re: why use CHAR.. _EVER_?
    ... when they only hold data that is 10 characters long. ... stuff like keys? ... SQL, by definition, ignores white-space at the end of CHAR data types. ... every column in search expressions, and extra space at the end of character ...
    (microsoft.public.sqlserver)
  • Re: heeeeeeeeeeeeeeeellllllllllllllppppppppppppppppppppp
    ... Why is using char* a bad thing and why using sprintf a bad thing to, ... can be up to MAX_PATH characters). ... LPSTR lpMsgBuf; ... MessageBox(NULL, lpMsgBuf, "GetLastError() for ...
    (microsoft.public.vc.mfc)
  • Re: heeeeeeeeeeeeeeeellllllllllllllppppppppppppppppppppp
    ... This means that if you develop the bad habit of using char * (left over ... It usually takes me five minutes to create a Unicode version of any of my apps, ... BOOL and bool are different data types. ... can be up to MAX_PATH characters). ...
    (microsoft.public.vc.mfc)
  • Re: Char and Varchar
    ... If the maximum length is short (<= 10 characters), ... maximum length, I also use CHAR. ... I use VARCHAR if long and short ...
    (microsoft.public.sqlserver.server)