我们如何重新使用任何MySQL-DB表中已删除的ID? [英] How can we re-use the deleted id from any MySQL-DB table?
问题描述
我们如何重新使用任何MySQL-DB表中已删除的ID?
How can we re-use the deleted id from any MySQL-DB table?
如果我要回滚已删除的ID,我们可以这样做吗?
If I want to rollback the deleted ID , can we do it anyhow?
推荐答案
可以通过找到最低的未使用ID并将其强制来实现,但这是非常糟糕的做法,主要是因为引用完整性:例如,该表中其他表的关系指向已删除的记录,如果重复使用ID,该记录将不再被识别为已删除".
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.
相关阅读:在mySQL手册中使用auto_increment
重新更新:即使您有正当的理由这样做,我也不认为有自动方法重新使用auto_increment
字段中的值.如果有的话,您将必须找到最低的未使用值(可能使用存储过程或外部脚本),并强制将其用作ID(如果可能的话).
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.).
这篇关于我们如何重新使用任何MySQL-DB表中已删除的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!