Results 1 to 5 of 5

Thread: [RESOLVED] How Char is advantageous over VarChar2 ??

  1. #1

    Thread Starter
    Lively Member amolt's Avatar
    Join Date
    Aug 2006
    Location
    INDIA
    Posts
    80

    Resolved [RESOLVED] How Char is advantageous over VarChar2 ??

    Hi All,
    Can someone tell me plz How Char datatype is advantageous over VarChar?
    How? and When to use Char?

    Thanks,

    amolt.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: How Char is advantageous over VarChar2 ??

    Varchar is advantageous over Char because space allocated grows dinamically.
    "The dark side clouds everything. Impossible to see the future is."

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How Char is advantageous over VarChar2 ??

    CHAR is advantageous over VARCHAR due to storage techiques.

    All CHAR columns are stored in the physical data (on disk) first - since the length of each of them is known to the engine. All VARCHAR data is then stored following this - with "pointers" to indicate the size of each of these columns. These pointers exist in every row - since column sizes vary so.

    So conventional wisdom would indicate that CHAR data is faster then VARCHAR. And that argument is debated often - and probably reasonably true.

    Which leads to the belief - by some people - that CHAR should be used whenever the length of the data is consistent in a column - such as a SOCIAL SECURITY NUMBER - which is always 9 characters.

    We personally do not support this belief.

    We always use VARCHAR - even for a VARCHAR(1) field that will always have a character in it.

    We like that the value in that column will be a "zero-length" string if the column is empty. As a matter of fact we really like the "trailing spaces" being removed by VARCHAR definition.

    So with that said we so like the VARCHAR() difference in storage and display of data that we don't mind taking the "hit" for speed - which is probably negligible anyway...

    That same goes for NULL columns!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Lively Member amolt's Avatar
    Join Date
    Aug 2006
    Location
    INDIA
    Posts
    80

    Re: How Char is advantageous over VarChar2 ??

    Hi szlamany,

    thanks for such a descriptive reply, it really helps me to find the difference.

    Rgds,
    amolt.

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: How Char is advantageous over VarChar2 ??

    I agree with szalamany. I used to use Char fields because I believed the so-called experts. But after spending considerable time adding Trim$ around recordset fields in VB programs I switched. As already mentioned using Char has diskspace and processing benefits but they add costs elsewhere (imho of course)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width