Page 1 of 1

can I reset a mysql database's auto_increment

Posted: Tue Jan 21, 2003 10:11 am
by MedaXis
hi all
I have a table with a field for the id which is auto_incremented and a field for the names

I made a little script used for deleting rows.
let's say there are 6 rows with IDs (0001, 0002, 0003, 0004, 0005, 0006) and I delete the row with ID 0003, then I change the IDs (manually at the moment but I will write a script eventually) so the follow up on each other again, now I have the IDs 0001, 0002, 0003, 0004, 0005.
When I add another row using a script the new row will have an ID of 0007

can I set the auto_increment so that it will add just 1 to the last ID

I hope that makes sense,
Steve

Posted: Tue Jan 21, 2003 10:26 am
by twigletmac
The point of the auto-incrementing ID is that it is unique for each record - that is if a record is deleted the rest are not renumbered to go back into sequence.

Why do the records have to have sequential ID's?

Mac

Posted: Tue Jan 21, 2003 11:33 am
by MedaXis
well...I needed the ID's to identify the records outside phpmyAdmin but I see your point, they don't have to be sequential...sorry :)

thank you

Steve