MySQL Data Type description explanation

Source: Internet
Author: User

There are three main types in MySQL: text (text), number (numeric), and date/time (date/time) types.

Text Type:

Data Type Description
CHAR (size) Holds a fixed-length string (which can contain letters, numbers, and special characters). Specifies the length of the string in parentheses. A maximum of 255 characters.
VARCHAR (size) Saves variable-length strings (which can contain letters, numbers, and special characters). Specifies the maximum length of the string in parentheses. A maximum of 255 characters. Note: If the value is longer than 255, it is converted to the TEXT type.
Tinytext Holds a string with a maximum length of 255 characters.
TEXT Holds a string with a maximum length of 65,535 characters.
Blob For BLOBs (Binary Large OBjects). Store up to 65,535 bytes of data.
Mediumtext Holds a string with a maximum length of 16,777,215 characters.
Mediumblob For BLOBs (Binary Large OBjects). Store up to 16,777,215 bytes of data.
Longtext Holds a string with a maximum length of 4,294,967,295 characters.
Longblob For BLOBs (Binary Large OBjects). Store up to 4,294,967,295 bytes of data.
ENUM (x,y,z,etc.) Allows you to enter a list of possible values. The maximum of 65,535 values can be listed in the ENUM list. If the inserted value does not exist in the list, a null value is inserted.

Note: These values are sorted in the order that you entered them.

Possible values can be entered in this format: ENUM (' X ', ' Y ', ' Z ')

SET Similar to ENUM, except that set can contain up to 64 list items and set stores more than one selection.

Number type:

data type description
TINYINT (size) signed-128 to 12 7, unsigned 0 to 255.
SMALLINT (size) signed range 32768 to 32767, unsigned 0 to 65535, size defaults to 6.
mediumint (size) signed range 8388608 to 8388607, unsigned range is 0 to 16777215. The size defaults to 9
INT (size) signed range 2147483648 to 2147483647, and the unsigned range is 0 to 4294967295. Size defaults to
BIGINT (size) signed range is 9223372036854775808 to 9223372036854775807, unsigned range is 0 to 18446 744073709551615. Size defaults to
float (size,d) A small number with a floating decimal point. Specifies the maximum number of digits to display in the size parameter. Specifies the maximum number of digits to the right of the decimal point in the D parameter.
double (size,d) A large number with a floating decimal point. The fixed maximum number of digits is indicated in the size parameter. Specifies the maximum number of digits to the right of the decimal point in the D parameter.
Decimal (size,d) is a DOUBLE type stored as a string, allowing a fixed decimal point. Specifies the maximum number of digits to display in the size parameter. Specifies the maximum number of digits to the right of the decimal point in the D parameter.

Note: the size above represents not the exact length stored in the database, such as int (4), which does not store only 4-length digits.

There is actually no relationship between how much storage space an int (size) occupies. Int (3), int (4), and Int (8) All occupy 4 btyes of storage space on disk. Is that the way it is displayed to the user is a little different, the int (M) is the same as the int data type.

For example:

1, the value of int is 10 (specify Zerofill)

int(9) Displays the result as 000000010int(3) showing the result as 010       

It's a different length, it's a four-byte space.

Date Type:

The
data type description
Date () dates. Format: Yyyy-mm-dd

Comment: supported range is from ' 1000-01-01 ' to ' 9999-12-31 '

DATETIME () * combination of date and time. Format: yyyy-mm-dd HH:MM:SS

Comment: supported range is from ' 1000-01-01 00:00:00 ' to ' 9999-12-31 23:59:59 '

TIMESTAMP () * timestamp. The TIMESTAMP value is stored using the number of seconds to date in the Unix era (' 1970-01-01 00:00:00 ' UTC). Format: yyyy-mm-dd HH:MM:SS

Comment: supported range is from ' 1970-01-01 00:00:01 ' UTC to ' 2038-01-09 03:14:07 ' UTC

time () . Format: HH:MM:SS

Comment: supported range is from ' -838:59:59 ' to ' 838:59:59 '

year () 2 bit or 4-bit format year.

Note: The 4-bit format allows values from 1901 to 2155. The 2-bit format allows values from 70 to 69, representing 1970 to 2069.

* Even if DATETIME and TIMESTAMP return the same format, they work in a different way. In an INSERT or UPDATE query, TIMESTAMP automatically sets itself to the current date and time. TIMESTAMP also accepts different formats, such as YYYYMMDDHHMMSS, YYMMDDHHMMSS, YYYYMMDD, or YYMMDD.

SQL Common data types:

Data Type Description
CHARACTER (N) Character/String. Fixed length n.
VARCHAR (n) or
CHARACTER VARYING (N)
Character/String. Variable length. Maximum length n.
BINARY (N) Binary string. Fixed length n.
BOOLEAN Store TRUE or FALSE values
VARBINARY (n) or
BINARY VARYING (N)
Binary string. Variable length. Maximum length n.
INTEGER (P) Integer value (no decimal point). Accuracy p.
SMALLINT Integer value (no decimal point). Accuracy 5.
INTEGER Integer value (no decimal point). Accuracy 10.
BIGINT Integer value (no decimal point). Accuracy 19.
DECIMAL (P,s) Exact value, precision p, number of digits after the decimal point S. For example, decimal (5,2) is a number that has a 2-digit number after a 3-digit decimal point before the decimal point.
NUMERIC (P,s) Exact value, precision p, number of digits after the decimal point S. (Same as DECIMAL)
FLOAT (P) Approximate value, mantissa accuracy p. A floating-point number using a 10-based exponential notation. The size parameter of this type consists of a single number that specifies the minimum precision.
REAL Approximate value, mantissa accuracy 7.
FLOAT Approximate value, mantissa accuracy 16.
DOUBLE PRECISION Approximate value, mantissa accuracy 16.
DATE Stores the value of the year, month, and day.
Time Stores the value of hours, minutes, and seconds.
TIMESTAMP Stores the value of the year, month, day, hour, minute, and second.
INTERVAL Consists of a number of integer fields, representing a period of time, depending on the type of interval.
ARRAY An ordered set of elements of fixed length
MULTISET Unordered collection of variable-length elements
Xml Storing XML data

Reference Address: http://www.runoob.com/sql/sql-datatypes.html

MySQL Data Type description explanation

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.