ZEROFILL
Example
Section titled “Example”CREATE TABLE SampleTable ( sample_id INT(5) ZEROFILL);INSERT INTO SampleTable (sample_id)VALUES (1), (42), (300);
SELECT * FROM SampleTable;Output
Section titled “Output”+-----------+| sample_id |+-----------+| 00001 || 00042 || 00300 |+-----------+Explanation
Section titled “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.