Jump to content

Reset where an auto-increment starts?


Mal1
Go to solution Solved by Mal1,

Recommended Posts

I know people are going to say don't delete rows or ignore gaps but this situation is different than most.

 

I have a database that had products in it up to id 900 (ish). We had a developer work on the site who messed us about and is now not working on it anymore. Going into the database I notice there's no almost 1800 rows in the database. These 900 extra rows are completely blank and do not have data stored on other tables (there are other tables linked but there was no data added for them).

 

My problem is that the id gets used to display a reference number, so now not only do I have 900 rows in a table that have no data in them (can't be good for speed?) but I have products with a reference (which people use to search) that jumps from 900 to 1800.

 

So, should I delete the rows? Tried deleting a few but then went to add a new product (row) using out back-end admin and rather than setting the new id to say 1800 it sets it to 1811 (if I have deleted 1801-1810). Is there a way to make it start again from the last database entry/row? I'm not trying to make it not auto-increment just somehow reset it back to what is was then allow it to auto-increment as it should.

 

Sorry, noob here.

Link to comment
Share on other sites

if they are blank rows, then one option is to delete al the blank rows, then run :

 

ALTER TABLE `you_table_name_here` AUTO_INCREMENT = <the last row +1, so if you have 900 records it would be 901>;

 

thats should reset the counter on the auto increment for you. Backup your data first though !!!!!!!!!!!

Link to comment
Share on other sites

  • Solution

if they are blank rows, then one option is to delete al the blank rows, then run :

 

ALTER TABLE `you_table_name_here` AUTO_INCREMENT = <the last row +1, so if you have 900 records it would be 901>;

 

thats should reset the counter on the auto increment for you. Backup your data first though !!!!!!!!!!!

Thanks, I found this on Google actually and just came back to mark it as solved, tested it and it seemed to work so backed up then deleted BETWEEN 900 useless IDs then set it back to 910.

 

Hopefully it doesn't screw up something else down the line.

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.