What does MySQL data type int (M) mean?

Source: Internet
Author: User
Tags mysql manual

The integer types in the MySQL data type is a bit strange. You might see an int data type such as int (3), int (4), int (8). When I first approached MySQL, I thought int (3) took up less storage space than int (4), and int (4) used less storage space than int (8).

Later, see the MySQL manual and find that you understand the mistake.

Int (m): M indicates the maximum display width for integer types.

In the integer data type, M represents the maximum display width.


Originally, in Int (m), the value of M has nothing to do with how much storage space the Int (m) occupies. Int (3), int (4), and Int (8) All occupy 4 btyes of storage space on disk. To put it bluntly, the Int (M) is the same as the int data type except that the way it is displayed to the user is a little different.

In addition,Int (M) can only be combined with Zerofill to make us see the difference clearly.

Mysql> drop table if exists t;mysql> CREATE TABLE t (id int zerofill);mysql> INSERT into T (ID) values; mysql> ; SELECT * FROM t;+------------+| ID         |+------------+| 0000000010 |+------------+mysql> ALTER TABLE t change column ID ID int (3) zerofill;mysql> SE Lect * FROM t;+------+| ID   |+------+|  010 |+------+mysql>mysql> ALTER TABLE t change column ID ID int. (4) zerofill;mysql> select * FROM t;+------+| ID   |+------+| 0010 |+------+mysql>mysql> INSERT INTO T (ID) VALUES (1000000);mysql> select * from t;+-------- -+| ID      |+---------+|    0010 | | 1000000 |+---------+


As can be seen from the above test, "(M)" Specifies the width of the int type numeric display, if the field data type is int (4), then: When the value of 10 o'clock is displayed, the left side of the "00", when the value 100 is, on the left to fill "0"; When the value 1000000 is displayed, The specified width "(4)" has been exceeded, so it is output as-is.

When using integer types in MySQL data types (tinyint, smallint, mediumint, Int/integer, bigint), there is no point in adding a "(M)" to the data type after the non-special requirements.

In addition, in MySQL data type , integer and int are synonymous. Which one to use, see for yourself.

What does MySQL data type int (M) mean?

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.