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

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

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

        <tfoot id='Ol81e'></tfoot>

        SQLite 自增非主键字段

        时间:2023-07-17
          <bdo id='nIgqH'></bdo><ul id='nIgqH'></ul>

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

              2. <tfoot id='nIgqH'></tfoot>

              3. <legend id='nIgqH'><style id='nIgqH'><dir id='nIgqH'><q id='nIgqH'></q></dir></style></legend>
                1. <small id='nIgqH'></small><noframes id='nIgqH'>

                  本文介绍了SQLite 自增非主键字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以让非主键在每次插入时自动递增?

                  例如,我想要一个日志,其中每个日志条目都有一个主键(供内部使用)和一个修订号(我希望自动递增的 INT 值).

                  作为一种解决方法,这可以通过序列来完成,但我相信 SQLite 不支持序列.

                  解决方案

                  插入时可以做select max(id)+1.

                  例如:

                  INSERT INTO Log (id, rev_no, description)VALUES ((SELECT MAX(id) + 1 FROM log), 'rev_Id', 'some description')

                  请注意,这将在空表上失败,因为不会有 id 为 0 的记录,但您可以添加第一个虚拟条目或将 sql 语句更改为:

                  INSERT INTO Log (id, rev_no, description)值 ((SELECT IFNULL(MAX(id), 0) + 1 FROM Log), 'rev_Id', 'some description')

                  Is it possible to have a non-primary key to be auto-incremented with every insertion?

                  For example, I want to have a log, where every log entry has a primary key (for internal use), and a revision number ( a INT value that I want to be auto-incremented).

                  As a workaround, this could be done with a sequence, yet I believe that sequences are not supported in SQLite.

                  解决方案

                  You can do select max(id)+1 when you do the insertion.

                  For example:

                  INSERT INTO Log (id, rev_no, description) VALUES ((SELECT MAX(id) + 1 FROM log), 'rev_Id', 'some description')

                  Note that this will fail on an empty table since there won't be a record with id is 0 but you can either add a first dummy entry or change the sql statement to this:

                  INSERT INTO Log (id, rev_no, description) VALUES ((SELECT IFNULL(MAX(id), 0) + 1 FROM Log), 'rev_Id', 'some description')

                  这篇关于SQLite 自增非主键字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在不使用触发器的情况下在 Oracle 中自动递增 下一篇:没有 ORDER BY 的 SQL Server 2005 ROW_NUMBER()

                  相关文章

                2. <tfoot id='8NoWt'></tfoot>
                3. <small id='8NoWt'></small><noframes id='8NoWt'>

                    <bdo id='8NoWt'></bdo><ul id='8NoWt'></ul>
                  <legend id='8NoWt'><style id='8NoWt'><dir id='8NoWt'><q id='8NoWt'></q></dir></style></legend>

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