Re: why use CHAR.. _EVER_?

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



thanks; that is very helpful

-Aaron


Mike C# wrote:
<aaron.kempf@xxxxxxxxx> wrote in message
news:1159815989.569683.204390@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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--

Shhhh. You could start a holy war with talk like that :) There are a lot
of folks who believe strictly, 100%, in Natural Keys - which are very often
character-based instead of numeric; much less INT or 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?

SQL, by definition, ignores white-space at the end of CHAR data types. This
includes CHAR, VARCHAR, NCHAR, NVARCHAR, etc. To take your example further
you can put 'aaron ' in a CHAR variable and 'aaron' in a VARCHAR and
they will match as well.

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

I think the standard calls for adding extra padding to the search
expression, but the net result is the same.

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

it just seems inconsistent the way that they do it.

It's a leftover from the days when all that was available was fixed-width
CHAR types. It actually is pretty handy since you don't have to RTRIM()
every column in search expressions, and extra space at the end of character
type data will not affect your results.

.



Relevant Pages

  • Re: why use CHAR.. _EVER_?
    ... stuff like keys? ... i just dont understand why 'aaron' matches to 'aaron ' ... uses CHAR instead of VarChar. ... it is always 5 characters and you want to preserve any leading 0's. ...
    (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)