The difference between MySQL Int (m) and int (m)

Source: Internet
Author: User

It is expected that most of the friends who start contact with MySQL will have this problem: what does the value of int (M) mean?


according to the relevant information summarized below:

Int (m) Zerofill, plus zerofill after M shows a little bit of effect, such as int (3) Zerofill, you insert into the database is 10, is actually inserted as 010, which adds a 0 in front of the add . Assuming that Int (3) and Int (ten) are not Zerofill, they are no different. M is not used to limit the number of int . The maximum and minimum values of int (M) are related to undesigned , and the following illustration is illustrated.

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. The range is from 1 to 64, assuming M is ignored. Default Feeling 1

2.tinyint[(m)] [UNSIGNED] [Zerofill] M default feel 4

A 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) .

The zero value is considered false. Non- zero values are considered true.

4.smallint[(m)] [UNSIGNED] [Zerofill] M default feel 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 feel 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 Feel 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 feel 20

A large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

*: The M represented here is not the detailed length stored in the database

In fact, when we choose the type that uses int, whether it is int (3) or int (11). It stores 4 bytes of length in a database. When using int (3), assume that you are entering 10. Will default to you storage bit 010, that is, this 3 represents a default length, when you are less than 3, will help you not all, when you more than 3, no matter what the impact.

The day before yesterday group asked me what is the difference between int (10) and int (11). At that time, it was the difference between the lengths, now look, they are in addition to the storage of a slightly different. There is no difference in the time we use it. Int (10) can also represent a value of 2147483647, an int (11) can also be represented.


We usually do not add this option when creating a database, so we can say that there is no difference between them.

The difference between MySQL Int (m) and int (m)

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.