我正在尝试使用对象和子对象创建数据库文件.例如,
第一个表是用于存储变化的罐子.每个jar条目都有一个自动增量主ID键和有关jar的数据,如高度,直径等等.
第二张表将包含硬币.每个硬币都有一个ID(需要?),还有它所包含的罐子的ID和它的数据(如价值,年份等).
我的问题是当一个被删除时自动增量键会发生什么?说你有4个罐子:
1
2
3
4
你删除了2号.剩下的罐子会重新编号为123吗?还是会有差距?如果有间隙,是否填充,以便创建的下一个jar的ID为2?或者下一个仍然是5?
谢谢
解决方法:
您可以在sqlite AUTOINCREMENT文档中了解相关内容:
The usual algorithm is to give the
newly created row a ROWID that is one
larger than the largest ROWID in the
table prior to the insert. If the
table is initially empty, then a ROWID
of 1 is used. If the largest ROWID is
equal to the largest possible integer
(9223372036854775807) then the
database engine starts picking
positive candidate ROWIDs at random
until it finds one that is not
previously used. If no unused ROWID
can be found after a reasonable number
of attempts, the insert operation
fails with an SQLITE_FULL error.
简而言之,插入4行后,删除第二行,然后在末尾插入另一行,ids将是:
1 3 4 5
原文地址:https://codeday.me/bug/20190610/1211482.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。