<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 自增非主键字段

        SQLite auto-increment non-primary key field(SQLite 自增非主键字段)
          <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 自增非主键字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  <tfoot id='8NoWt'></tfoot>
                2. <small id='8NoWt'></small><noframes id='8NoWt'>

                    <bdo id='8NoWt'></bdo><ul id='8NoWt'></ul>
                        <tbody id='8NoWt'></tbody>
                      <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>