gpt4 book ai didi

Android SQLite 自动增量

转载 作者:IT王子 更新时间:2023-10-28 23:50:09 32 4
gpt4 key购买 nike

我目前有一个名为 User 的表,它有一个 id 列,它被创建为

'整数主键'

假设我创建了两个用户,所以表的 id 为 1 和 2

如果我删除第二个用户并创建第三个 id 为 2 的用户,我需要将其设为 3

看来 Android 正在选择下一个可用的 id,如何将其更改为更像序列号?

问候

最佳答案

使其INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL。这是the docs说:

If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then... the ROWID chosen for the new row is at least one larger than the largest ROWID that has ever before existed in that same table.

The behavior implemented by the AUTOINCREMENT keyword is subtly different from the default behavior. With AUTOINCREMENT, rows with automatically selected ROWIDs are guaranteed to have ROWIDs that have never been used before by the same table in the same database. And the automatically generated ROWIDs are guaranteed to be monotonically increasing.

关于Android SQLite 自动增量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8434819/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com