MySQL in int (m) in M

Source: Internet
Author: User

Http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html

This M is maximum display width. What is maximum display width? See the following example is easy to explain, note zerofill :

mysql> CREATE TABLE B (b int (4));
Query OK, 0 rows affected (0.25 sec)

mysql> insert into B values (12345);
Query OK, 1 row Affected (0.00 sec)

Mysql> SELECT * from B;
+-------+
| B |
+-------+
| 12345 |
+-------+
1 row in Set (0.00 sec)

mysql> ALTER TABLE B change b b int (one);
Query OK, 1 row Affected (0.00 sec)
Records:1 duplicates:0 warnings:0

Mysql> SELECT * from B;
+-------+
| B |
+-------+
| 12345 |
+-------+
1 row in Set (0.00 sec)

mysql> ALTER TABLE B change b b int (one) Zerofill;
Query OK, 1 row Affected (0.00 sec)
Records:1 duplicates:0 warnings:0

Mysql> SELECT * from B;
+-------------+
| B |
+-------------+
| 00000012345 |
+-------------+
1 row in Set (0.00 sec)

mysql> ALTER TABLE B change b b int (4) Zerofill;
Query OK, 1 row affected (0.08 sec)
Records:1 duplicates:0 warnings:0

Mysql> SELECT * from B;
+-------+
| B |
+-------+
| 10000 |
+-------+
1 row in Set (0.00 sec)

mysql> ALTER TABLE B change b b int (6) Zerofill;
Query OK, 1 row affected (0.01 sec)
Records:1 duplicates:0 warnings:0

Mysql> SELECT * from B;
+--------+
| B |
+--------+
| 012345 |
+--------+
1 row in Set (0.00 sec)

The above example shows that this M represents the width of the display, and he follows Zerofill to make sense. Even if the value of M previously set is smaller than the actual length of the number, it has no effect on the data.

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.