What is the difference between an int (3) and an int (11) in MySQL?

Source: Internet
Author: User

Note: M here is not a specific length stored in the database, it was always mistaken for int (3) to store only 3-length numbers, and int (11) would store 11-length numbers, which is a big mistake.

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.

To see the different effects remember to add the Zerofill value when creating the type, indicating that it is filled with 0, otherwise the effect is not visible.

We don't usually add this option when we create a database, so we can say there's no difference between them.

That which didn ' t kill me makes me stronger

When the Declaration field is of type int, int is four bytes, a byte 8 bits, or 4*8=32, the number of digits that can be represented is 2 32 (2^32 = 4 294 967 296 digits).

4 294 967 296 numbers that is 0~4 294 967 295, of course, if you distinguish the sign, the number will be smaller.

Take a look at the picture below

What is the difference between an int (3) and an int (11) in MySQL?

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.