The difference between a MySQL int (3) and an int (11)
Summing up, int (m) Zerofill, plus zerofill after M to show a little bit of effect, such as int (3) Zerofill, you insert into the database is 10, then the actual insertion of 010, that is, add a 0 in front. if int (3) and int (10) Without Zerofill, they are no different. M is not used to limit the number of int. The maximum and minimum values for int (M) are related to undesigned, as shown in the bottom diagram.
Mysql> CREATE table t (t Int (3) zerofill);
Query OK, 0 rows Affected (0.00 sec)
mysql> INSERT INTO t set t = 10;
Query OK, 1 row Affected (0.00 sec)
Mysql> select * from T;
+--+
| T |
+--+
| 010 |
+--+
1 row in Set (0.11 sec)
Zerofill with default width, the same as int (10):
Mysql> CREATE table t (t int zerofill);
Query OK, 0 rows affected (0.02 sec)
mysql> INSERT INTO t set 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 table t (t int);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO t set t = 10;
Query OK, 1 row affected (0.01 sec)
Mysql> select * from T;
+--+
| T |
+--+
| 10 |
+--+
1 row in Set (0.00 sec)
Reproduced above from http://hi.baidu.com/nancy0754/blog/item/2f3ea13a957a27d7d5622535.html
1 bytes = 8 bit, a byte can represent the data length of 2 8 times 11111111 in the computer that is
-128 to 127
1.BIT[M]
Bit field type, M represents the number of digits per value, range from 1 to 64, if M is ignored, default is 1
2.tinyint[(M)] [UNSIGNED] [Zerofill] M defaults to 4
Very 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). Zero value is considered false. Non-zero values are considered true.
4.smallint[(M)] [UNSIGNED] [Zerofill] M defaults to 6
A small integer. The signed range is-32768 to 32767. The unsigned range is 0 to 65535.
5.mediumint[(M)] [UNSIGNED] [Zerofill] M defaults to 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 defaults to 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 defaults to 20
Large integers. The signed range is-9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.
Note: Here m is not a specific length stored in the database, it is always wrong to think that Int (3) can store only 3-length digits, and int (11) Stores 11-length digits.
In fact, when we choose to use the type of int, whether int (3) or int (11), it stores the length of 4 bytes in the database, and when you use INT (3) If you enter 10, the default is to store bit 010, This means that the 3 represents a default length, when you are less than 3, will help you incomplete, when you more than 3, there is no impact.
The day before yesterday group Tube asked me int (10) and int (11) What is the difference, at that time feel that is the difference between the length of it, now look, they are in addition to the storage time slightly different, in our use when there is no difference. Int (10) can also represent the value int (11) of 2147483647.
To see the different effects remember to create the type when adding Zerofill this value, indicating that the 0 padding, otherwise do not see the effect.
We usually do not add this option when we create the database, so we can say that there is no difference between them.
That which didn ' t kill me makes me stronger
Thank you for reading this article, I hope to help you, thank you for the support of this site!