The difference between MySQL int (3) and int (11)

Source: Internet
Author: User

Int (m) Zerofill, plus Zerofill after M shows a little bit of effect,

For example int (3) Zerofill, you insert into the database is 10, then the actual insert is 010, that is, add a 0 in front of the

if int (3) and int (10) 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, as shown in:

1 bytes = 8 bit, a byte can represent a maximum of 2 of the length of the data is 8 square, in the computer is also 128 to 127

tinyint a byte, smallint two bytes, mediumint three bytes, int four bytes, BIGINT eight bytes.

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

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

Bool,boolean

is a synonym for tinyint (1). The zero value is considered false. Non-zero values are considered true

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

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

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

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

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 int (3) or int (11), it stores 4 bytes of length in the database,

When using int (3) Zerofill, if you enter 10, you will be given a default storage bit of 010

In other words, this 3 represents the default length, when you are less than 3, will help you complete, when you more than 3, there is no impact (data deposit, take out, display has 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 storage of a slightly different,

There is no difference when we use it. 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.

+------------------------------------------Gorgeous Split-line-----------------------------------------------+

tinyint (1) and tinyint (3) are no different, occupy Byte is a, storage range is the same!

tinyint (1) and tinyint (3) Save 123 can be saved (both can be normal extraction, display),

And if tinyint (3) Zerofill, insert the value 12, will be stored 012,zerofill auto left 0, this is the limit display length.

Int (3) Zerofill, when the data inserted is less than 3 bits, the left auto-fill 0, when more than 3 bits, there is no effect (the data deposit, extraction and display have no effect).

The difference between MySQL int (3) and int (11)

Related Article

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.