Mal1 Posted February 26, 2013 Share Posted February 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
gristoi Posted February 26, 2013 Share Posted February 26, 2013 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 !!!!!!!!!!! Quote Link to comment Share on other sites More sharing options...
Solution Mal1 Posted February 26, 2013 Author Solution Share Posted February 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.