我们如何从任何MySQL-DB表中重用已删除的id?

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?

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.).

You shouldn't do it.
Don't think of it as a number at all.
It is not a number. It's unique identifier. Think of this word - unique. No record should be identified with the same id.

1.

As per your explanation provided "@Pekka, I am tracking the INsert Update and delete query..." I assume you just some how want to put your old data back to the same ID.

In that case you may consider using a delete-flag column in your table.

If the delete-flag is set for some row, you shall consider program to consider it deleted. Further you may make it available by setting the delete-flat(false).

Similar way is to move whole row to some temporary table and you can bring it back when required with the same data and ID.

Prev. idea is better though.

2.

If this is not what you meant by your explanation; and you want to delete and still use all the values of ID(auto-generated); i have a few ideas you may implement: - Create a table (IDSTORE) for storing Deleted IDs. - Create a trigger activated on row delete which will note the ID and store it to the table. - While inserting take minimum ID from IDSTORE and insert it with that value. If IDSTORE is empty you can pass NULL ID to generate Auto Incremented number.

Of course if you have references / relations (FK) implemented, you manually have to look after it, as your requirement is so.

Further Read: http://www.databasejournal.com/features/mysql/article.php/10897_2201621_3/Deleting-Duplicate-Rows-in-a-MySQL-Database.htm