With Zerofill
when you select a column, it pads the displayed value with zeros up to the field size specified in the column definition. It does not affect the values longer than the display width. Note that usage of ZEROFILL
also implies UNSIGNED
.
ZEROFILL
affects only how it is displayed. Its use and the display have no effect on how the data is stored.
The bellow example demonstrates the use of ZEROFILL
:
CREATE TABLE product(code INT(8) ZEROFILL NOT NULL, price INT(8) NOT NULL);
INSERT INTO product(code,price) VALUES
(10, 10),
(12, 12),
(123, 123),
(123456789, 500)
SELECT * FROM `product`
Result :