Results 1 to 3 of 3

Thread: varchar or char

  1. #1
    Join Date
    Oct 2004
    Location
    In cousin's house
    Posts
    303

    Unanswered: varchar or char

    hi,
    I just want to knew if what is the field to be use in order to save resources . The length of my input is <= 50 character. The varchar or char. Anyone have an input about my issue.

    thanks,
    Popskie

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Depends on what exactly you mean by resources and what kind of data is going into the columns. In general, VARCHAR is used for variable length strings. If your data is always going to be 50 characters long, use CHAR. If there will be large discrepancies in the length of strings that will be entered, consider using VARCHAR.

    CHAR columns take up the designated amount of space for each record. VARCHAR columns only use the required amount of space + 1 extra byte. I believe that CHAR columns search faster, but VARCHARS take up less space (when used with variable length strings) and thus cut down on table size, which also keeps searches fast. For 50 characters, I don't think it would make much of a difference. If your entries are all going to be 50 characters, use CHAR, but for variable length strings, it is more logical to use VARCHAR.


    Code:
    CHAR(50) 
      -- will always hold 50 characters (pads shorter with whitespace.)
      -- will always use 50 bytes
    
    VARCHAR(50) 
      -- will hold up to 50 characters (no padding shorter strings.)
      -- will use string length + 1 bytes
    http://dev.mysql.com/doc/refman/5.0/en/char.html

  3. #3
    Join Date
    Oct 2004
    Location
    In cousin's house
    Posts
    303
    ok thanks for ur idea.

Posting Permissions

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