gpt4 book ai didi

android - 在 Android Sqlite 中,ROWID 与主键相同吗?

转载 作者:搜寻专家 更新时间:2023-10-30 21:41:22 29 4
gpt4 key购买 nike

我有一个具有以下架构的表:

public static final String PRIMARY_KEY = "_id";
public static final String TASK_NAME = "name";
public static final String TASK_DESCRIPTION = "description";
public static final String IS_TASK_COMPLETED = "is_completed";
public static final String IS_TASK_DELETED = "is_deleted";
public static final String TASK_START_DATE = "start_date";
public static final String TASK_START_TIME = "start_time";
public static final String ESTIMATED_TASK_END_DATE = "end_date";
public static final String TIMESTAMP = "timestamp";

在一个 fragment 中,我使用 insert() 在表中插入一行方法。我知道这会返回插入行的 rowId 但在 this 中我读过的线程

If a table contains a column of type INTEGER PRIMARY KEY, then that column becomes an alias for the ROWID. You can then access the ROWID using any of four different names, the original three names described above or the name given to the INTEGER PRIMARY KEY column. All these names are aliases for one another and work equally well in any context.

因此返回的 rowId 将与主键相同。但是,如果删除一行并插入另一行,那么 rowId 是否与 primary key value "id" 相同?

最佳答案

所有表(忽略 exceptions)都有一个行 ID。

当没有列声明为 INTEGER PRIMARY KEY 时,rowid 与其他列分开:

CREATE TABLE A ( _id INT PRIMARY KEY, name TEXT ); -- not "INTEGER"

| rowid | _id | name |
+-------+-----+------+
| 1 | 1 | this |
| 2 | 2 | that |
| 3 | 30 | NULL | -- does not need to be the same

如果一个INTEGER PRIMARY KEY列,rowid和声明的列名都是相同值的别名:

CREATE TABLE B ( _id INTEGER PRIMARY KEY, name TEXT );

| rowid | name |
| = _id | |
+-------+------+
| 1 | this |
| 2 | that |
| 3 | NULL |

关于android - 在 Android Sqlite 中,ROWID 与主键相同吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38289416/

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