Databases 4 min read

Does MySQL int(1) Limit Your Values? Uncovering Display Width and ZEROFILL

This article explains why the number in MySQL int(N) does not restrict the column’s numeric range, demonstrates that int(1) can store the full unsigned range, and shows how ZEROFILL combined with a display width pads numbers with leading zeros.

dbaplus Community
dbaplus Community
dbaplus Community
Does MySQL int(1) Limit Your Values? Uncovering Display Width and ZEROFILL

In MySQL, the integer type always occupies 4 bytes, giving an unsigned range of 0 to 4,294,967,295 regardless of the number in parentheses. The number in int(N) is only a display width hint and does not affect the actual storage capacity.

Demonstration of int(1) Capacity

Creating a table with an unsigned int(1) primary key and inserting the maximum unsigned value succeeds, proving that int(1), int(2), … int(10) all support the same range.

CREATE TABLE `user` (
  `id` int(1) unsigned NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `user` (`id`) VALUES (4294967295);
Query OK, 1 row affected (0.00 sec)

When Does the Number Matter? ZEROFILL

The display width becomes visible only when the ZEROFILL attribute is used. With int(4) ZEROFILL, MySQL pads values to four digits when displayed, while the stored value remains unchanged.

CREATE TABLE `user` (
  `id` int(4) unsigned ZEROFILL NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `user` (`id`) VALUES (1),(10),(100),(1000);
SELECT * FROM user;
+------+
| id   |
+------+
| 0001 |
| 0010 |
| 0100 |
| 1000 |
+------+

The output shows leading zeros added for numbers with fewer than four digits, but the underlying storage is still the original integer.

Key Takeaways

The number in int(N) does not limit the numeric range; it only defines display width.

To see the effect of display width, combine it with ZEROFILL.

ZEROFILL is useful for formatting identifiers (e.g., student numbers) to a fixed length without altering the stored value.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLmysqlintZEROFILLdisplay width
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.