MySQL: numeric type, mysql numeric type

Source: Internet
Author: User

MySQL: numeric type, mysql numeric type

Column Type:

1. numeric type

  • Integer type:
Type Bytes occupied Minimum value (Signed/unsigned) Maximum value (Signed/unsigned)
TINYINT 1 -128/0 127/255
SMALLINT 2 -32768/0 32767/65535
MEDIUMINT 3 -2147483648/0 214748647/4294967295
INT 4 -2147483648/0 2147483647/4294967295
BIGINT 8 -9223372036854775808/0 9223372036854775807/18446744073709551615

 

 

 

 

 

Tip: You can use the unsigned flag when defining it. If it is not written, it is considered as signed.

Example of inserting a value in the correct range in the table tb_int:

When you try to insert a value out of the range, the following error occurs:

In addition to defining the preceding numeric types, you can also define the display width (to achieve unified display by specifying the display width ).

Format: type (M) M indicates the minimum display width

This attribute usually requires leading zero padding to achieve the goal and become zerofill.

Add column c to tb_int, and set the display width to at least 2;

Insert the following data and observe the results:

Boolean bool type, equivalent to the alias of tinyint (1. MySQL considers 0 as false, and a non-0 value as true.

  • Decimal type (floating point + fixed point)

Floating Point Number (decimal point can be changed ):

Single precision (4 bytes): float (about 6 digits by default)

Double Precision (8 bytes): double (about 16 digits by default)

Supported scientific Notation: 123.56*10 ^ 3 should be written in the form of 123.56E3

You can create a table tb_2 as follows:

In fact, when creating a table tb_2, another method is usually used to control the value range:

Float (5, 2) indicates the number of input values in the column a. The total number of digits cannot exceed 5, with a maximum of 2 decimal places and a maximum of 3 integers;

Double (8, 3.

When you enter two numbers that meet the preceding requirements, the output is as follows:

The range of values that float (999.99) can represent is ~ 999.99.

Insert data in scientific notation. The displayed results are as follows:

Fixed number of digits (fixed decimal places): The number of digits is not stored in the exact number of bytes, but is extended (approximately every 9 digits, 4 bytes)

Decimal (M, D): M indicates the total number of digits, D indicates the number of decimal places, and the range also exists. Controlled by M and D

M is 10 by default, and D is 0 by default.

 

Both fixed points and floating point numbers support zerofill, and floating point numbers also support unsigned.

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.