MySQL database learning----MySQL data type

Source: Internet
Author: User

All data is stored in binary form in the calculation, whereas a 8-bit binary number represents 1 bytes.

Usually we say how many bytes a data type is, which means that the data type can represent how many bits of binary number, and the binary number can be converted to decimal number, so that the data type can be represented by how much decimal number!

For example, MySQL data type int, we all know that int can represent 4 bytes, that is, 32-bit binary, 32-bit binary can represent unsigned decimal number 0~4394967295.

So we assign the int data type a number between 0 and 4394967295, and if it goes beyond this range, the system will give an error.

MySQL data types are divided into several categories:

One: Integral type

Data type (display width)

integer type
< Span style= "font-family: ' Microsoft Yahei ';" >int 4 0~4394967295 -2147483648~2147483647

The general int type is enough for us to use when we usually use it, and there are some less commonly used in the integral type: TINYINT (1), SMALLINT (2), Mediumint (3), Integer (4), BIGINT (8).

Two: floating-point and fixed-point numbers

Data type (M, D)

Integral type Number of bytes Range of negative values Range of non-negative values
FLOAT 4

-3.402823466e+38~

-1.175494351E-38

0 and 1.175494351e-38~

3.402823466E+38

The M parameter is called precision, which represents the total length of the data, not decimal points.

The d parameter is called the scale, which refers to the length after the decimal point.

Other floating-point types also have double (8), fixed-point decimal (M, d), or Dec (M, d), because the floating-point data in MySQL is error-based, and it is recommended to use DEC fixed-point if needed.

Three: Date and Time type

integral type value range 0 value
datetime 8

1000-01-01 00:00:00~

9999-12-31 23:59:59

0000-00-00 00:00:00

Indicates that datetime types are generally used for date times, and there are some infrequently used

Year (1): Indicates only years, range 1901~2155

Date (4): Only the date of the year, the range 1000-01-01~9999-12-31

Time (3): Indicates hours, minutes, seconds. Range -838:59:59~838:59:59

TIMESTAMP (4): The format is the same as datetime, but the range of representations is small.

Four: String type

String Type (M)

CHAR (m): Fixed for M-byte lengths to store strings.

VARCHAR (m): The maximum length of M bytes, the actual length is +1 of the length of the string being deposited.

TEXT (M): Up to 65535 bytes, the actual storage space is +2 of the length of the string being deposited.

Enum (' VALUE1 ', ' VALUE2 ',...): Enum type, the range can only be the value in the list, MySQL is stored in the list of the serial number, if the inserted value is not in the list will be an error. Up to 65,535 values in a list

SET (' VALUE1 ', ' VALUE2 ',...): Similar to enum type, but with a maximum of 64 values in the list.

5:2 binary Type

Cond...

MySQL database learning----MySQL data type

Related Article

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.