user2635024
user2635024

Reputation: 37

MySQL Auto Increment Initial value not working

I am trying set a primary key to auto increment in this format "00001, 00002 ...." , but I can't get the leading zeroes to stay there. The code that I am using to try and do this is as follows.

alter table bids auto_increment=00001;

I also tried implementing this while I was creating the table but it was not working. Any idea why?

Upvotes: 0

Views: 351

Answers (1)

Miloš Rašić
Miloš Rašić

Reputation: 2279

auto_increment works on INT fields which contain binary representation of number. This does not specify how your numbers will be displayed. Have the application that uses your database pad the numbers with zeros before displaying them.

Alternately, you could use MySQL's LPAD function in your query like this:

SELECT LPAD(id, 5, '0') as padded_id FROM bids

Personally, I think this is the job of the application that uses the database, not of the database itself, but it's your choice.

Upvotes: 1

Related Questions