MySQL data type

Source: Internet
Author: User

I. Numeric type

Integer type Bytes Range (signed) Range (unsigned) Use
TINYINT 1 bytes (-128,127) (0,255) Small integer value
SMALLINT 2 bytes (-32 768,32 767) (0,65 535) Large integer value
Mediumint 3 bytes (-8 388 608,8 388 607) (0,16 777 215) Large integer value
int or integer 4 bytes (-2 147 483 648,2 147 483 647) (0,4 294 967 295) Large integer value
BIGINT 8 bytes (-9 233 372 036 854 775 808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) Maximum integer value
FLOAT 4 bytes ( -3.402 823 466 e+38,1.175 494 351 E-38), 0, (1.175 494 351 E-38, 3.402 823 466 351 e+38) 0, (1.175 494 351 e-38,3.402 823 466 e+38) Single-precision floating point value
DOUBLE 8 bytes (1.797 693 134 862 315 7 e+308,2.225 073 858 507 201 4 E-308), 0, (2.225 073 858 507 201 4 e-308,1.797 693 134 862 315 7 e+3 08) 0, (2.225 073 858 507 201 4 e-308,1.797 693 134 862 315 7 e+308) Double-precision floating-point number
Value
Decimail (M,D) m+2 bytes -10^38 +1 ~ 10^38-1 0 ~ 10^38-1 Precise decimal values

INT Type:

The 5 major integer types supported in MySQL are Tinyint,smallint,mediumint,int and BIGINT. These types are largely the same, except that the size of the values they store is not the same.

MySQL extends the SQL standard in the form of an optional display width indicator, so that when retrieving a value from the database, it can be extended to a specified length. For example, specify that a field is of type INT (6),

You can ensure that values with fewer than 6 contained numbers are automatically populated with spaces when retrieved from the database. It is important to note that using a width indicator does not affect the size of the field and the range of values that it can store.

In case we need to store a number that exceeds the permitted range for a field, MySQL is truncated and then stored according to the one end of the allowable range closest to it. And one of the more special places is,

MySQL will automatically be modified to 0 before the non-specified value is inserted into the table.

The UNSIGNED modifier specifies that the field only holds positive values. Because you do not need to save the positive and negative symbols of the numbers, you can save a "bit" space at the time of storage. thereby increasing the range of values that this field can store.

The Zerofill modifier specifies a value of 0 (not a space) that can be used to really complement the output. Use this modifier to prevent the MySQL database from storing negative values.

FLOAT, double type

The three floating-point types supported by MySQL are float, DOUBLE type. Float numeric types are used to represent single-precision floating-point numbers, whereas double numeric types are used to represent double-precision floating-point numbers.

As with integers, these types also have additional parameters: a display width indicator and a decimal point indicator. For example, the statement FLOAT (7,3) specifies that the value displayed will not exceed 7 digits, followed by a 3-digit number after the decimal point.

For the number of digits after the decimal point beyond the allowable range, MySQL automatically rounds it to the nearest value, and then inserts it.

Decimal type

Float accounts for 4 bytes, double is 8 bytes, and decimal (m,d) takes up m+2 bytes. If the maximum value of decimal (5,2) is 9999.99, the net has 7 bytes available. M and D have an effect on the value range of decimal (m,d). When the value is within its range and the number of decimal digits is higher, the decimal place is truncated directly. If the value is outside its range, it is filled with the maximum (small) value.

MySQL data type

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.