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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.