What is the difference between CHAR and VARCHAR data types?

Discussion in 'Website Development & Design' started by beingchinmay, Aug 17, 2015.

  1. beingchinmay

    beingchinmay
    uix_expand uix_collapse
    New Member

    Joined:
    Aug 4, 2015
    Messages:
    10
    Likes Received:
    1
    CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.
    VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column
     
  2. anirban09P

    anirban09P
    uix_expand uix_collapse
    New Member

    Joined:
    Dec 19, 2013
    Messages:
    28
    Likes Received:
    0
    PHP does not have a concept of variable type, I am assuming that your query is about the MySQL CHAR/VARCHAR variable.

    CHAR is a fixed length data type. CHAR(100) will take 100 characters of storage even if you enter less than 100 characters to that column.

    VARCHAR is a variable length data type. VARCHAR(100) will take only the required storage for the actual number of characters entered to that column.
     
    • Agree Agree x 1
  3. Perry Wiersma

    Perry Wiersma
    uix_expand uix_collapse
    New Member

    Joined:
    Dec 8, 2015
    Messages:
    11
    Likes Received:
    1
    VARCHAR is variable-length.

    CHAR is fixed length.

    If your content is a fixed size, you'll get better performance with CHAR.
     
  4. alexdisuza

    alexdisuza
    uix_expand uix_collapse
    Member

    Joined:
    Jun 19, 2013
    Messages:
    92
    Likes Received:
    2
    When using the fixed length data in column like mobile number, use Char.

    When using the variable length data in column like address, use VarChar.
     
  5. wyom

    wyom
    uix_expand uix_collapse
    New Member

    Joined:
    Jun 11, 2016
    Messages:
    7
    Likes Received:
    0
    Char
    Used to store character string value of fixed length.
    The maximum no. of characters the data type can hold is 255 characters.
    It's 50% faster than Varchar.
    Uses static memory allocation.
    Varchar
    Used to store variable length alphanumeric data.
    The maximum this data type can hold is up to 4000 characters.
    It's slower than Char.
    Uses dynamic memory allocation
     
  6. Ramona Vandusen

    Ramona Vandusen
    uix_expand uix_collapse
    New Member

    Joined:
    May 23, 2016
    Messages:
    18
    Likes Received:
    0
    char is a fixed-length data type or varchar is a variable length data type.
     
  7. w3web

    w3web
    uix_expand uix_collapse
    Member

    Joined:
    Mar 18, 2016
    Messages:
    89
    Likes Received:
    3
    If your website is dynamic so you need to use VarChar instead of Char, since you may not know what changes can be applied to your website content. So, i recommend to use varchar for dynamic websites.
     

Share This Page