Jump to content

Query to update auto incremented id numbers?


webguync

Recommended Posts

I have an auto incremented field in my table called id. The numbers were from 1-125. I had to delete one record with an id of 1. Now I want to change the numbering since it is from 2-125 now (back to 1 to the end). Is there a Query to do this without going into each individual record in PHP MyAdmin and doing it?

ok, well I am displaying the id info on a page using PHP so my numbering display is off now. The only other option I have is to re-upload my content to get the numbering order correct.

 

Again the purpose of the key is to provide uniqueness, and to facilitate joins to other related tables.  It is not a counter. 

 

With that said, what you can do is:

 

-reset the auto_increment counter for the table to 1

-drop the column

-re-add it

 

You can run these commands in the mysql client or use the sql panel of phpMyAdmin, or whatever mysql admin app you might be using. 

 

alter table yourtable auto_increment = 1
alter table yourtable drop id
alter table yourtable add id int unsigned primary key auto_increment first

 

ok, well I am displaying the id info on a page using PHP so my numbering display is off now. The only other option I have is to re-upload my content to get the numbering order correct.

No -- the "other option" you have is to number them properly -- with a counter.

 

gizmola has given you a way to fix this once -- but don't.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.