It is estimated that most of the friends who start contacting MySQL will have this problem: what does the value in int (M) mean?
According to the relevant information summarized below:
Int (M) ZerofillPlusZerofillAfterMShow a little bit of effect, likeInt (3) Zerofill,The one you inserted into the database wasTen,is actually inserted as010,Which is in front of adding a0.IfInt (3)AndInt (Ten)Do not addZerofill,Then they are no different. M is not used to limitintNumber of.Int (M)The maximum and minimum values of theundesignedAbout, the bottom of the picture has a description.
Mysql> CREATE TABLE Table_one (t int (3) zerofill);
Query OK, 0 rows Affected (0.00 sec)
Mysql> INSERT INTOTable_oneSet T = 8;
Query OK, 1 row Affected (0.00 sec)
Mysql> SELECT * FROMTable_one;
+--+
| T |
+--+
| 008 |
+--+
1 row in Set (0.11 sec)
Zerofill with default width, the same as int (10):
Mysql> CREATE TABLE table_two (t int zerofill);
Query OK, 0 rows affected (0.02 sec)
Mysql> INSERT INTOTable_twoSet t = 10;
Query OK, 1 row affected (0.02 sec)
Mysql> select * from T;
+ ———— +
| T |
+ ———— +
| 0000000010 |
+ ———— +
1 row in Set (0.08 sec)
Without Zerofill:
Mysql> CREATE TABLETable_3(t int);
Query OK, 0 rows affected (0.01 sec)
Mysql> INSERT INTOTable_3Set t = 10;
Query OK, 1 row affected (0.01 sec)
Mysql> select * from T;
+--+
| T |
+--+
| 10 |
+--+
1 row in Set (0.00 sec)
1 bytes = 8 bit, a byte can represent a maximum of 2 of the length of the data 8 square 11111111 in the computer is also
128 to 127
1.BIT[M]
Bit field type, M represents the number of bits per value, range from 1 to 64, if M is ignored, default is 1
2. Span style= "word-wrap:normal; Word-break:normal ">tinyint[( M )] [UNSIGNED] [zerofill] m default is 4
A small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.
3. BOOL,BOOLEAN
is a synonym for TINYINT (1) . The zero value is considered false. Non- zero values are considered true.
4.smallint[(m)] [UNSIGNED] [Zerofill] M default is 6
A small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.
5.mediumint[(m)] [UNSIGNED] [Zerofill] M default is 9
A medium-sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.
6. int[(m)] [UNSIGNED] [Zerofill] M default is 11
An integer of normal size. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.
7.bigint[(m)] [UNSIGNED] [Zerofill] M default is 20
A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.
*: The M here represents not the exact length stored in the database
In fact, when we choose the type of int, whether it is int (3) or int (11), it is stored in the database is 4 bytes of length, when using int (3) If you enter 10, will default to you storage bit 010, This means that the 3 is the default length, and when you are less than 3, it will help you not all, when you have more than 3 bits, there is no effect.
The day before yesterday group Tube asked me what is the difference between int (10) and int (11), then think is the difference between the length, now look, they are in addition to the time of storage in a slightly different, when we use the time there is no difference. an int (10) can also represent a value of 2147483647 for which int (11) can also be represented.
We don't usually add this option when we create a database, so we can say there's no difference between them.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The difference between MySQL Int (m) and int (m)