can I reset a mysql database's auto_increment

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

can I reset a mysql database's auto_increment

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
MedaXis
Forum Newbie
Posts: 16
Joined: Tue Nov 12, 2002 12:49 pm
Location: the netherlands

Post 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
Post Reply