mysql int data type length Learn notes

Source: Internet
Author: User
Tags numeric

1. Storage required for numeric type column types TINYINT 1 bytes SMALLINT 2 bytes mediumint 3 bytes INT 4 bytes
Int (m) in the integer data type, m represents the maximum display width.
in int (m), the value of M has nothing to do with how much storage space the Int (m) occupies.
and the number of digits also have no relationship int (3), int (4), int (8)
4 Btyes of storage space is used on the disk.

Int (M) is the same as the int data type, except that the field type is set Zerofill (0) slightly different.
The condition of the zero-complement:
mysql> desc test;
+-------+--------------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------------------+------+-----+---------+----------------+
| ID | Int (3) unsigned Zerofill | NO | PRI | NULL | auto_increment |
+-------+--------------------------+------+-----+---------+----------------+
1 row in Set (0.01 sec)
Mysql> select * from test;
+------+
| ID |
+------+
| 001 |
| 010 |
| 1234 |
+------+
3 Rows in Set (0.00 sec)
No 0:
mysql> desc test;
+-------+--------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+----------------+
| ID | Int (3) | NO | PRI | NULL | auto_increment |
+-------+--------+------+-----+---------+----------------+
1 row in Set (0.01 sec)
Mysql> select * from test;
+------+
| ID |
+------+
| 1 |
| 10 |
| 1234 |
+------+
3 Rows in Set (0.00 sec)
The feeling is to make it easy to typesetting


The length of FLOAT, double, and decimal refers to all digits (including the one after the decimal point), for example, Decimal (4,1) refers to the total number of digits to 4, 1 digits after the decimal point, or 999.9 if you insert 1234. Process is as follows


1.mysql> ALTER TABLE test add Realnum decimal (4,1);
2.Query OK, 2 rows affected (0.03 sec)
3.records:2 duplicates:0 warnings:0
4.
5.mysql> INSERT INTO Test (Id,realnum) values (2,1234);
6.Query OK, 1 row affected, 1 warning (0.05 sec)
7.
8.mysql> select * from test;
9.+------+---------+
10.| ID | Realnum |
11.+------+---------+
12.|    001 | NULL |
13.|    1234 | NULL |
14.|   002 | 999.9 |
15.+------+---------+
16.3 Rows in Set (0.02 sec)

The table lists the various numeric types and their allowable range and memory footprint.
Type size range (signed) range (unsigned) purpose
TINYINT 1 byte (-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. 402 823 466 e+38) Single precision
Floating-point values
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 8 315 7 e+308) 0, (2.225 073 858 507 201 4 e-308,1.797 693 134 862 315 7 e+308) Double precision
Floating-point values
Decimal to Decimal (m,d), if m>d, for m+2 otherwise d+2 dependent on M and d for values that depend on the value of M and d are small values
INT 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.