MySQL field length and display width

Source: Internet
Author: User

The display width of the integer value is specified in parentheses following the MySQL type keyword (for example, INT (11)). The optional display width specifies that the width is filled from the left when the value that is less than the specified width of the column is displayed. The display width does not limit the range of values that can be saved within the column, nor does it limit the display of values that exceed the specified width of the column.

so int (1) and int (11) are no different by default!!!

When combined with optional extended attribute Zerofill, the default supplemental space is replaced with 0. For example, for a column declared as int (5) Zerofill, the value 4 is retrieved as 00004. Note that if you save a value that exceeds the display width in an integer column, you will encounter problems when MySQL generates temporary tables for complex joins, because in these cases MySQL believes that the data fits the original column width.

All integer types can have an optional (non-standard) attribute of unsigned. Unsigned values can be used when you want to allow only non-negative numbers in a column and the column requires a large upper range of values. If you set the Zerofill extended Properties test, the default is unsigned (UNSIGNED)

So the characters in parentheses after int (1) and int (11) represent the width of the display, the display width of the integer column and the number of characters required by MySQL to display the value of the columns, and the size of the storage space required by the integer, the data limit of the type of int can be stored or 2147483647 ( Signed) and 4294967295 (unsigned). In fact, when we choose the type of int, whether int (1) or int (11), it stores the length of 4 bytes in the database.

Summarize:

Int (m) Zerofill, plus Zerofill after M to show a difference, such as int (3) Zerofill, you insert into the database is 10, the actual insert is 010, that is, add a 0 in front. if int (3) and int (10) Without Zerofill, they are no different. M is not used to limit the range of values stored in an int column. The maximum and minimum values of int (M) are related to unsigned.

MySQL field length and display width

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.