MySQL Data type analysis

Source: Internet
Author: User

CHAR, VARCHAR, TEXT

    • CHAR fixed length string, high space, fast
    • VARCHAR variable length string, small footprint, slow speed
    • The space behind the char is removed, and varchar does not remove
    • TEXT cannot have a default value
    • Efficiency of data Retrieval CHAR > VARCHAR > TEXT

ENUM ()

    • Each element of an enumeration has an ordinal number
    • Automatically remove the space behind the element
    • Value must be one of the enumerations when inserting data, except NULL
    • Only one value can be selected from the list

SET ()

    • You can select more than one value from the list, and multiple values are separated by commas
    • Save in a table with a binary value

Year:

    • Year saved 1901-2155
    • You can save the numeric form, or you can save the string form
    • When you enter a two-digit or two-bit string, the prefix is automatically preceded by 20 or 19.
    • When inserting a number 0 o'clock, save to 0000
    • When inserting a string 0 o'clock, save to 2000

Time:

    • By days: Hours: minutes: seconds
    • INSERT tablename VALUES (' 1 12:12:12 '); Save into 36:12:12
    • INSERT tablename VALUES (' 11:11 '); Save into 11:11:00
    • INSERT tablename VALUES (' 1234 '); Save into 00:12:34
    • INSERT tablename VALUES (' 12 '); Save into 00:00:12
    • INSERT tablename VALUES (' 0 '); Save into 00:00:00

DATE:

    • 1000-0101 ~ 9999-12-31
    • INSERT tablename VALUES (' 12-6-7 '); 2012-06-07
    • INSERT tablename VALUES (' 12/6/7 '); 2012-06-07
    • INSERT tablename VALUES (' 120607 '); 2012-06-07
    • INSERT tablename VALUES ('[email protected]/7 '); 2012-06-07
    • General time save timestamp with integer type

Floating-point types:

    • When inserting data in decimal place too many, float, double will automatically round; Decimal produces a warning.
    • Inside decimal is saved as a string
    • When a value is inserted as a string, float, double saves the result may be incorrect, but the decimal is not wrong
    • When the accuracy requirement is high, you should use decimal

MySQL Data type analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.