Meaning of int (M) in MySQL

Source: Internet
Author: User

When creating a database field and encountering a numeric type, such as int (4), I once thought it was a length. Later I tested it and found that no matter how many fields I set, the length of the inserted data is not affected. The related explanations are as follows:

From: http://www.ccvita.com/175.html

Meaning of X in MySQL int (X)

This optional width specification is used to show the left fill of values whose width is shorter than the column width when the value is displayed, instead of limiting the width of the value stored in the column, or limiting the number of digits that can be displayed that exceed the specified width of the column. Note: If you store a larger value in an integer column that exceeds the display width, you may encounter problems when MySQL generates temporary tables for some complex joins, in this case, MySQL trust that all values are suitable for the original column width.

Int itself is 4 bytes. bigint is 8 bytes. So the meaning of int (X) is that int determines the bytes in data storage. X represents the expected column width.

In an SQL statement, int indicates the type of the field to be created, int indicates the integer type, and 11 indicates the length of the field.

This indicates the display width.
The display width of an integer column is different from the number of characters required by mysql to display the value of this column. It has nothing to do with the size of the storage space required by this integer. For example, no matter how many characters the display width is set, bigint occupies 8 bytes.

 

From: http://matt-u.javaeye.com/blog/380670

As an extension to the ANSI/ISO sql92 standard, MySQL also supports integer types such as tinyint, mediumint, and bigint. Another extension is that MySQL allows you to specify the display format of an integer value at will, which is achieved through the basic keyword of the type followed by a bracket (for example, INT (4 )). This optional width specification is used to show the left fill of values whose width is shorter than the column width when the value is displayed, instead of limiting the width of the value stored in the column, or limiting the number of digits that can be displayed that exceed the specified width of the column. When used together with the optional extension property zerofill, the space filled by default is replaced by zero. For example, a column is defined as int (5) zerofill, And the inserted value 4 is 00004 when retrieved. Note: If you store a larger value in an integer column that exceeds the display width, you may encounter problems when MySQL generates temporary tables for some complex joins, in this case, MySQL trust that all values are suitable for the original column width.

 

However, I have never tried zerofill in MySQL (Windows.

 

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.