ZEROFILL

ZEROFILL is a MySQL attribute that pads the displayed value of numeric columns with zeroes up to the display width specified in column definition. It affects display only, not storage or calculations.

Example

CREATE TABLE SampleTable (
sample_id INT(5) ZEROFILL
);
INSERT INTO SampleTable (sample_id)
VALUES (1), (42), (300);
SELECT * FROM SampleTable;

Output

+-----------+
| sample_id |
+-----------+
| 00001 |
| 00042 |
| 00300 |
+-----------+

Explanation

In the above example, ZEROFILL is used as a column option for the sample_id column. This option zeroes are filled in the left until the specified length is met. On insert, if we insert a number that requires fewer digits than the field size, extra zeroes will be added on the left of the number. The result shows 00001, 00042, 00300 instead of 1, 42, 300.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.