Skip to content
Advertisement

How can we re-use the deleted id from any MySQL-DB table?

How can we re-use the deleted id from any MySQL-DB table?

If I want to rollback the deleted ID , can we do it anyhow?

Advertisement

Answer

It may be possible by finding the lowest unused ID and forcing it, but it’s terribly bad practice, mainly because of referential integrity: It could be, for example, that relationships from other tables point to a deleted record, which would not be recognizable as “deleted” any more if IDs were reused.

Bottom line: Don’t do it. It’s a really bad idea.

Related reading: Using auto_increment in the mySQL manual

Re your update: Even if you have a legitimate reason to do this, I don’t think there is an automatic way to re-use values in an auto_increment field. If at all, you would have to find the lowest unused value (maybe using a stored procedure or an external script) and force that as the ID (if that’s even possible.).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement