• <bdo id='R8Wyr'></bdo><ul id='R8Wyr'></ul>

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

      <legend id='R8Wyr'><style id='R8Wyr'><dir id='R8Wyr'><q id='R8Wyr'></q></dir></style></legend>

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

      1. 使自动增量填充以前删除的数字

        Make auto increment fill previously deleted number(使自动增量填充以前删除的数字)
          <bdo id='9PnJj'></bdo><ul id='9PnJj'></ul>
            <tbody id='9PnJj'></tbody>

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

                  <tfoot id='9PnJj'></tfoot>

                  <small id='9PnJj'></small><noframes id='9PnJj'>

                1. 本文介绍了使自动增量填充以前删除的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能的重复:
                  使用未使用的主键

                  我创建了一个带有自动增量的 id 列的表现在,当我删除该表中 id 为 8,12,30 的行时.

                  I created a table with an id column with auto increment Now when I deleted the rows with the id's 8,12,30 in that table.

                  现在,当我插入一条新记录时,我想将下一条记录插入 8 然后是 12 等等.

                  Now when I insert a new record I want to insert the next record into 8 then 12 etc..

                  有没有办法让 MySQL 自动增量来为我做这件事?

                  Is there a way to get MySQL auto increment to do this for me?

                  我尝试将自动增量设置为某个数字,但我不想那样做.

                  I tried to set autoincrement to some number, but I don't want to do it that way.

                  推荐答案

                  那时您不想使用自动递增的列.如果要填补空白,请将其设置为 int 列并处理存储过程或插入中的逻辑.

                  You don't want to use an auto-incrementing column then. If you want to fill in the gaps, set it to an int column and handle the logic in stored proc or insert.

                  由于它是一个 int 列,您可以按数字对它们进行排序.只需执行 SELECT Ids FROM Table Order By Ids 即可获取所有 Id 并检查返回数据集中的差距.

                  Since it's an int column, you can order them numerically. Just do a SELECT Ids FROM Table Order By Ids to get all of the Ids and check for the gaps in the returned dataset.

                  可能有更流畅的方法,但您可以使用游标循环结果,并与在整个循环中递增的 INT 变量进行比较.当您发现间隙(不匹配)时 - 中断循环并使用该 INT 值作为您的 INSERT id.

                  There's probably a smoother way of doing this, but you could loop the results with a cursor and compare to an INT variable that increments throughout the loop. When you find a gap (no match) - break the loop and use that INT value as your INSERT id.

                  我不会为您编写代码,但这些是帮助您朝着正确方向前进的一些步骤.它应该是你应该能够处理的一个非常基本的编程.

                  I won't write your code for you, but those are some steps to get you going in the right direction. It should be a really basic bit of programming you should be able to handle.

                  希望这会有所帮助.

                  正如其他人所指出的,最好的做法是留下间隙.除非桌子上有一些长度上限并且 Id 必须是 1-30(奇怪),否则不要管它.填补空白没有任何好处.

                  As others have noted, your best move is to just leave the gaps. Unless there's some cap on the table as far as length and Ids MUST be 1-30 (weird), leave it alone. There's no benefit to filling in the gaps.

                  要考虑的另一件事:如果您出于某种原因确实必须保留 1-30,请不要删除您的行.添加一列以将每一行标记为活动或不活动,然后只需在需要时更新非活动的行,然后将它们标记为活动.这是非常hacky,但你的要求有点hacky,所以...

                  One more thing to consider: if you really do have to keep 1-30 for some reason, don't delete your rows. Add a column to flag each row as active or not and then just update the rows that are inactive when you need to and then flag them as active. This is VERY hacky, but your requirement is kinda hacky, so...

                  这篇关于使自动增量填充以前删除的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                  SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                  How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                  Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                  INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                  How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)

                  <tfoot id='9UafU'></tfoot>

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

                            <bdo id='9UafU'></bdo><ul id='9UafU'></ul>