• <legend id='4EuID'><style id='4EuID'><dir id='4EuID'><q id='4EuID'></q></dir></style></legend>
      <tfoot id='4EuID'></tfoot>

      • <bdo id='4EuID'></bdo><ul id='4EuID'></ul>

      <small id='4EuID'></small><noframes id='4EuID'>

      1. <i id='4EuID'><tr id='4EuID'><dt id='4EuID'><q id='4EuID'><span id='4EuID'><b id='4EuID'><form id='4EuID'><ins id='4EuID'></ins><ul id='4EuID'></ul><sub id='4EuID'></sub></form><legend id='4EuID'></legend><bdo id='4EuID'><pre id='4EuID'><center id='4EuID'></center></pre></bdo></b><th id='4EuID'></th></span></q></dt></tr></i><div id='4EuID'><tfoot id='4EuID'></tfoot><dl id='4EuID'><fieldset id='4EuID'></fieldset></dl></div>

        如何重用 auto_increment 值?

        时间:2023-07-17

          <tfoot id='UzGhq'></tfoot>
            <tbody id='UzGhq'></tbody>

          1. <legend id='UzGhq'><style id='UzGhq'><dir id='UzGhq'><q id='UzGhq'></q></dir></style></legend>
            <i id='UzGhq'><tr id='UzGhq'><dt id='UzGhq'><q id='UzGhq'><span id='UzGhq'><b id='UzGhq'><form id='UzGhq'><ins id='UzGhq'></ins><ul id='UzGhq'></ul><sub id='UzGhq'></sub></form><legend id='UzGhq'></legend><bdo id='UzGhq'><pre id='UzGhq'><center id='UzGhq'></center></pre></bdo></b><th id='UzGhq'></th></span></q></dt></tr></i><div id='UzGhq'><tfoot id='UzGhq'></tfoot><dl id='UzGhq'><fieldset id='UzGhq'></fieldset></dl></div>

              1. <small id='UzGhq'></small><noframes id='UzGhq'>

                  <bdo id='UzGhq'></bdo><ul id='UzGhq'></ul>
                  本文介绍了如何重用 auto_increment 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能的重复:
                  mysql中id的碎片(auto_increment列)

                  我的数据库中有此列.假设它的名字是threadid".它包含为每个线程分配的唯一 id 以进行区分.

                  I have this column in my database. Let's say its name is 'threadid'. It contains unique ids given to each thread for distinction.

                  线程ID987654321

                  threadid 9 8 7 6 5 4 3 2 1

                  假设我删除了 ID 为 5 和 6 的线程.

                  Let's say I have deleted threads with id 5 and 6.

                  线程ID9874321

                  threadid 9 8 7 4 3 2 1

                  但是当删除后有提交时,给那个线程的唯一id是10.不是5.我觉得这不整洁.

                  But when there is a submission after the deletion, the unique id given to that thread is 10. not 5. I think this is not neat.

                  如何获得列中的最小可能值?(在本例中为 5.)

                  How do I get the least possible value in the column? (in this case, 5.)

                  我认为我可以使用 MIN() 获得列的最小值并保持 +1 直到我获得未使用的唯一值,但我认为这太复杂了.

                  I think I can get the minimum value of the column using MIN() and keep +1 until I get the unused, unique value, but I think that's too complicated.

                  有没有什么简单的方法可以做到这一点?

                  Is there any simple way to do this?

                  谢谢.

                  推荐答案

                  我同意其他人的看法,即实现自己的查找最小开放数是一个非常糟糕的主意.但是在我工作的地方,我们得到了一组封闭的数字,当一个数字空闲时,我们必须重用.

                  I agree with the rest of everyone where it is a very bad idea to implement your own find minimal open number. But at where I work, we are given a closed set of number and when a number is free up, we must reuse.

                  这是我们如何做到的.

                  我们不删除行,而是将每列的所有值设置为空,所以你要做的是SELECT min(id) WHERE columnA IS NULL,如果返回了什么,我们重用,否则插入新行.

                  We do not delete the row, but set all values of every column null, So what you do is SELECT min(id) WHERE columnA IS NULL, and if this returns something, we reuse, otherwise, insert a new row.

                  这篇关于如何重用 auto_increment 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SQL Server 标识列值从 0 而不是 1 开始 下一篇:mysql 无法从存储引擎读取自动增量值

                  相关文章

                • <legend id='UbZ1e'><style id='UbZ1e'><dir id='UbZ1e'><q id='UbZ1e'></q></dir></style></legend>
                  <i id='UbZ1e'><tr id='UbZ1e'><dt id='UbZ1e'><q id='UbZ1e'><span id='UbZ1e'><b id='UbZ1e'><form id='UbZ1e'><ins id='UbZ1e'></ins><ul id='UbZ1e'></ul><sub id='UbZ1e'></sub></form><legend id='UbZ1e'></legend><bdo id='UbZ1e'><pre id='UbZ1e'><center id='UbZ1e'></center></pre></bdo></b><th id='UbZ1e'></th></span></q></dt></tr></i><div id='UbZ1e'><tfoot id='UbZ1e'></tfoot><dl id='UbZ1e'><fieldset id='UbZ1e'></fieldset></dl></div>

                    <tfoot id='UbZ1e'></tfoot>
                    • <bdo id='UbZ1e'></bdo><ul id='UbZ1e'></ul>

                    <small id='UbZ1e'></small><noframes id='UbZ1e'>