使用未使用的主键 [英] Using unused primary keys

查看:120
本文介绍了使用未使用的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何重用auto_increment值?

我有一张自动递增 ID -column的表,因为它是主键,但我遇到了'问题'只要删除,就会产生差距。这当然不是问题,但它看起来不是很整洁。是否有一种简单的方法可以让MySQL使用第一个未使用的 ID -number,而不是<$ c中的' next '号码$ C>序列?我希望我的问题有道理。

I have a table which has an auto-increment ID-column as it's primary key, but am running into the 'problem' that whenever a key is deleted, that creates a gap. This is of course not a problem as such, but it doesn't look very neat. Is there an easy way to get MySQL to use the first available unused ID-number, instead of the 'next' number in the sequence? I hope my question makes sense.

推荐答案

你想要完成的事情,恕我直言,不是一个好主意。考虑到这一点;还有其他可能与您刚刚删除的主键相关联。

What you want to accomplish, IMHO, is not a very good idea. Take this into account; there are other Tables that might be associated with the primary key that you have just deleted.

假设您在与已删除 主键相关联的其他表上有现有值:
当您从间隙中插入一个带有主键的新条目时,您将拥有与之关联的其他表格。你不会想要的。除非当然,如果您在删除主键时清除表格的所有,那就是很多工作。 删除Cascade 可能不够用。

Assuming that you have existing values on other tables associated with the deleted primary key: When you insert a new entry with primary key that was taken from the gap, you will have then values that are associated with the other tables. You wouldn't want that. Unless ofcourse, if you clean ALL of your tables when you delete a primary key, and that's a lot of work. Delete Cascade might not be enough for the most.

这篇关于使用未使用的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆