MySQL Int (M) detailed description

Source: Internet
Author: User

When I set up the Database tutorial field, when I encountered the number type, such as int (4), I once thought it was length, then I found that no matter how much I set, it did not affect the length of the inserted data, and I searched the relevant explanations on the Internet as follows:


MySQL tutorial the meaning of x in int (x)
This optional width specification is used when the value is displayed the width of some values that are shorter than the width of the column is displayed, not to limit the width of the values stored in the column, nor to limit the number of digits that can be displayed that exceed the value of the specified width of the column. Note that if you store a larger value in an integer column that exceeds the width of the display, you may experience problems when MySQL generates temporary tables for some complex joins (join), because in this case, MySQL trusts that all values are appropriate for the original column width.

and int itself is 4 bytes bigint is 8 bytes so the meaning of int (x) is int determines the byte x of the data store indicates the column width of the desired data

int represents the type of field you want to create in an SQL statement, int represents an integral type, and 11 represents the length of the field.

This represents the width of the display
The display width of the whole series and how many characters does MySQL need to display the column value, it has nothing to do with the size of the storage space required by the integer, for example, regardless of how many characters the display width is set, the bigint occupies 8 bytes.

As an extension of the Ansi/iso sql92 Standard, MySQL also supports integral type tinyint, mediumint, and bigint. Another extension is that MySQL supports the display format of arbitrarily specifying an integer value, which is implemented by following the basic keyword of the type followed by a bracket (for example, int (4)). This optional width specification is used when the value is displayed the width of some values that are shorter than the width of the column is displayed, not to limit the width of the values stored in the column, nor to limit the number of digits that can be displayed that exceed the value of the specified width of the column. When used with an optional extended property Zerofill, the default padding space is replaced by 0. For example, a column is defined as int (5) Zerofill, and the value 4 inserted is 00004 when retrieved. Note that if you store a larger value in an integer column that exceeds the width of the display, you may experience problems when MySQL generates temporary tables for some complex joins (join), because in this case, MySQL trusts that all values are appropriate for the original column width.

But I've never tried the Zerofill function in MySQL (under Windows).


Int (m), Integer (m) 32-bit int (4 bytes ...)

In fact, this m and int can represent the range does not matter, as long as you choose the Int,int is 4 bytes, 1 bytes 8 bits, if the unsigned number can be expressed as a range of 0-------232-1, you can store any number in this range.

But it is not to say that it does not matter, there is a zerofll in MySQL, when the table was selected 0 fill after the storage will be a great difference, then if you choose Int (4) You store 12 then the database is stored 0012, if you fill in 12345, At this time it exceeds his specified width and is stored as-is.

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.