Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

primary key is an auto increment field, how can i reuse #'s

Status
Not open for further replies.

anthracite98

Programmer
Feb 19, 2001
3
US
basic example

users table:
userID | username
-----------------
1|joe
2|jeff
3|nancy
4|phil

userID is unique and autoincrement, so when i insert, i dont specify userID. if i delete jeff, then insert dave, dave gets inserted as userID:5. Is there anyway to automatically recover/reuse the deleted #'s??

I'm sure i could write some script to check all the numbers using a loop, and when one isn't found, to use that # in the insert statement, but i'm wondering if there is an easier way.

thanks,
-mo
 
This comes up a fair bit. No you can't easily reuse ID's, and theres really no benefit in renumbering them at mysql level. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top