Data Types in MySQL

Discussion in 'MySQL' started by pradeep, Jul 7, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    TEXT TYPES

    CHAR( ) A fixed section from 0 to 255 characters long.
    VARCHAR( ) A variable section from 0 to 255 characters long.
    TINYTEXT A string with a maximum length of 255 characters.
    TEXT A string with a maximum length of 65535 characters.
    BLOB A string with a maximum length of 65535 characters.
    MEDIUMTEXT A string with a maximum length of 16777215 characters.
    MEDIUMBLOB A string with a maximum length of 16777215 characters.
    LONGTEXT A string with a maximum length of 4294967295 characters.
    LONGBLOB A string with a maximum length of 4294967295 characters.

    The ( ) brackets allow you to enter a maximum number of characters will be used in the column.

    Code:
    VARCHAR(20)
    CHAR and VARCHAR are the most widely used types. CHAR is a fixed length string and is mainly used when the data is not going to vary much in it's length. VARCHAR is a variable length string and is mainly used when the data may vary in length.

    CHAR may be faster for the database to process considering the fields stay the same length down the column. VARCHAR may be a bit slower as it calculates each field down the column, but it saves on memory space. Which one to ultimatly use is up to you.

    Using both a CHAR and VARCHAR option in the same table, MySQL will automatically change the CHAR into VARCHAR for compatability reasons.

    BLOB stands for Binary Large OBject. Both TEXT and BLOB are variable length types that store large amounts of data. They are similar to a larger version of VARCHAR. These types can store a large piece of data information, but they are also processed much slower.

    NUMBER TYPES

    TINYINT( ) -128 to 127 normal
    0 to 255 UNSIGNED.
    SMALLINT( ) -32768 to 32767 normal
    0 to 65535 UNSIGNED.
    MEDIUMINT( ) -8388608 to 8388607 normal
    0 to 16777215 UNSIGNED.
    INT( ) -2147483648 to 2147483647 normal
    0 to 4294967295 UNSIGNED.
    BIGINT( ) -9223372036854775808 to 9223372036854775807 normal
    0 to 18446744073709551615 UNSIGNED.
    FLOAT A small number with a floating decimal point.
    DOUBLE( , ) A large number with a floating decimal point.
    DECIMAL( , ) A DOUBLE stored as a string , allowing for a fixed decimal point.

    The integer types have an extra option called UNSIGNED. Normally, the integer goes from an negative to positive value. Using an UNSIGNED command will move that range up so it starts at zero instead of a negative number.

    DATE TYPES

    DATE YYYY-MM-DD.
    DATETIME YYYY-MM-DD HH:MM:SS.
    TIMESTAMP YYYYMMDDHHMMSS.
    TIME HH:MM:SS.

    MISC TYPES

    ENUM ( ) Short for ENUMERATION which means that each column may have one of a specified possible values.
    SET Similar to ENUM except each column may have more than one of the specified possible values.

    ENUM is short for ENUMERATED list. This column can only store one of the values that are declared in the specified list contained in the ( ) brackets.

    Code:
    ENUM('y','n')
    You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted.

    SET is similar to ENUM except SET may contain up to 64 list items and can store more than one choice.
     
  2. fand2nd

    fand2nd New Member

    Joined:
    Sep 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Yeah nice findings, keep it up.
     
  3. seangtz

    seangtz New Member

    Joined:
    Jun 6, 2008
    Messages:
    126
    Likes Received:
    3
    Trophy Points:
    0
    I'm still beginner in MySQL, this information will help me to get more knowledge.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice