Mysql int (3) and int (11) Differences, mysqlint

Source: Internet
Author: User

Mysql int (3) and int (11) Differences, mysqlint

Difference between mysql int (3) and int (11)

In summary, int (M) zerofill, followed by zerofill, then M shows a little effect. For example, if int (3) zerofill is inserted into the database as 10, it is actually inserted as 010, that is, add a 0. if int (3) and int (10) do not add zerofill, there is no difference between them. M is not used to limit the number of int. the maximum and minimum values of int (M) are related to undesigned values.

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 |
+ ---- +
| 1, 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)

Above Reprinted from http://hi.baidu.com/nancy0754/blog/item/2f3ea13a957a27d7d5622535.html

1 bytes = 8 bit. The maximum length of a byte can be 2 to the power of 8. 11111111 is also in the computer.

-128 to 127

1. BIT [M]

Bit Field type. M indicates the number of digits of each value, ranging from 1 to 64. If M is ignored, the default value is 1.

2. TINYINT [(M)] [UNSIGNED] [ZEROFILL] M is 4 by default

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. The non-zero value is true.

4. SMALLINT [(M)] [UNSIGNED] [ZEROFILL] M is 6 by default

A small integer. The signed range is-32768 to 32767. The unsigned range is 0 to 65535.

5. MEDIUMINT [(M)] [UNSIGNED] [ZEROFILL] M is 9 by default

An integer of medium size. The signed range is-8388608 to 8388607. The unsigned range is 0 to 16777215.

6. INT [(M)] [UNSIGNED] [ZEROFILL] M is 11 by default

An integer of the normal size. The signed range is-2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

7. BIGINT [(M)] [UNSIGNED] [ZEROFILL] M is 20 by default

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

Note: Here M represents not the specific length stored in the database. In the past, I always mistakenly thought that int (3) can only store three numbers in length, int (11) it stores 11 length numbers, which is a big mistake.

In fact, when we select the int type, whether it is int (3) or int (11), it stores 4 bytes in the database, when int (3) is used, if you input 10, the storage space 010 will be provided by default. That is to say, this 3 represents the default length, when you have less than three places, it will not help you. When you have more than three places, there will be no impact.

The day before yesterday, the Group Administrator asked me what is the difference between int (10) and int (11). I thought it was the difference in length. Now, there is no difference between them in terms of storage. Int (10) can also represent the value of 2147483647 int (11.

To check the effect, remember to add the zerofill value when creating the type, indicating to fill it with 0; otherwise, the effect will not be displayed.

We usually do not add this option when creating databases, so there is no difference between them.

That which didn't kill me makes me stronger

Thank you for reading this article and hope to help you. Thank you for your support on this site!

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.