重置自动增量有什么危害吗? [英] Is there any harm in resetting the auto-increment?

查看:160
本文介绍了重置自动增量有什么危害吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个1亿行,它变得太大了。
我看到很多差距。 (因为我删除,添加,删除,添加。)

I have a 100 million rows, and it's getting too big. I see a lot of gaps. (since I delete, add, delete, add.)

我想用自动增量来填补这些空白。
如果我重置it..有任何harM?

I want to fill these gaps with auto-increment. If I do reset it..is there any harM?

如果我这样做,它会填补空白吗?:

If I do this, will it fill the gaps?:

mysql> ALTER TABLE tbl AUTO_INCREMENT = 1;


推荐答案

潜在的非常危险,

您建议将序列重新设置为1。它将只产生1,2,3,4,5,6,7,...等等,不管这些数字是否在一个差距。

What you propose is resetting the sequence to 1 again. It will just produce 1,2,3,4,5,6,7,.. and so on, regardless of these numbers being in a gap or not.

更新:根据马丁的回答,由于涉及的危险,MySQL甚至不会让你这样做。它会将计数器重置为至少当前值+1。

Update: According to Martin's answer, because of the dangers involved, MySQL will not even let you do that. It will reset the counter to at least the current value + 1.

再次考虑间隙原因的存在的真正问题。

Think again what real problem the existence of gaps causes. Usually it is only an aesthetic issue.

如果数字太大,切换到更大的数据类型(bigint应该是足够的)。

If the number gets too big, switch to a larger data type (bigint should be plenty).

这篇关于重置自动增量有什么危害吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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