Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL field structure

Tags:

mysql

I have a MySQL table data type integer field. the value is stored as 1, 2, 3 .., 10000.

I want to format it with starting from 00001, 00002, 0003 etc., (the whole number to be 5 digit).

Is there any function to do?

or how do i set it manually in phpMyAdmin..

like image 498
Vincent Dagpin Avatar asked Apr 17 '26 07:04

Vincent Dagpin


1 Answers

You can change the column type to INT(5) ZEROFILL. From the documentation:

When used in conjunction with the optional extension attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004.

Example:

CREATE TABLE table1(x INT(5) ZEROFILL);
INSERT INTO table1 VALUES(4);
SELECT * FROM table1;

Result:

00004
like image 141
Mark Byers Avatar answered Apr 18 '26 20:04

Mark Byers