Column Type of the MySQL database (field type)

Source: Internet
Author: User
A MySQL database table is a two-dimensional table consisting of one or more data columns.
Each data column has its specific type, which determines how MySQL views the column data. We can store integer values in character-type columns, mySQL treats it as a string.
MySQL has three types of columns: numeric, string, and date/time.
In the big category, the column type is the same as the numerical type, and there are only three types. However, each column type can be subdivided.
The following describes the types of columns in detail.

Data column type of the numeric class
The numeric column types include integer and floating point types.

Tinyint: a positive integer with a very small size of 1 byte, with the symbol:-128 ~ 127, without symbols: 0 ~ 255
Smallint: 2-byte small integer, with the symbol:-32768 ~ 32767, without symbols: 0 ~ 65535
Mediumint: A 3-byte integer of medium size, with the symbol-8388608 ~ 8388607, without symbols: 0 ~ 16777215
INT: 4-byte standard integer, with the symbol:-2147483648 ~ 2147483647, without symbols: 0 ~ 4294967295
Bigint: 8-byte big integer, with the symbol:-9223372036854775808 ~ 9233372036854775807, without symbols: 0 ~ 18446744073709551615
Float: 4-byte Single-precision floating point number. Minimum non-zero value: +-1.175494351e-38; maximum non-zero value: +-3.402823466e + 38
Double: 8-byte double-precision floating point number, minimum non-zero value: +-2.225074255072014e-308, maximum non-zero value: +-1.7976931348623157e + 308
Decimal: A floating point number expressed as a string in m + 2 bytes. Its value range is variable, determined by the values of M and D.

Integer Data column type

MySQL has five types of Integer Data columns: tinyint, smallint, mediumint, Int, and bigint. The difference between them is that the value range is different, and the storage space is also different.
Adding the unsigned attribute to the integer data column can disable negative numbers. The value starts from 0.

When declaring an integer data column, we can specify a display width m (1 ~ 255), such as int (5), specifying the display width to 5 characters. If the display width is not specified for it, MySQL will specify a default value for it. The display width is only used for display, and the value range and occupied space cannot be limited. For example, INT (3) occupies 4 bytes of storage space, and the maximum allowed value is not 999, the maximum value allowed by the int type.

Float data column type

MySQL has three float data column types: float, double, and decimal.
The floating point data type has a maximum value and a minimum non-zero value. The minimum non-zero value determines the accuracy of this type.

After MySQL 4.0.2, float and double can both specify the unsigned attribute. When this attribute is specified, the value range is not moved to the positive number range, but is simply removed from the negative part of the floating point type.

The floating point type also has M (1 ~ 255) and D (1 ~ 30, and cannot be greater than the M-2 ). Display width and decimal places, respectively. M and D are optional in float and double. By default, when MySQL version is later than 3.23.6, float and double types are saved as the maximum precision supported by hardware. The m and D values of decimal are optional after mysql3.23.6. The default D value is 0, and the M value is 10.

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.