java - 如何在 sqlite 中使用自动增量变量?

标签 java sqlite

这是我在 sqlite 中的代码: stmt.execute("如果不存在人员则创建表(姓名文本,ID INTEGER PRIMARY KEY AUTOINCRMENT)");

但是当我在 Navicat 中看到我的表格并且当我想使用它时,它全部为空。我想像整数(1,2,...)一样使用它。我应该怎么办? 请帮助我...

最佳答案

一个简单的谷歌查询结果如下:

摘要

The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed.

In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID (except in WITHOUT ROWID tables) which is always a 64-bit signed integer.

On an INSERT, if the ROWID or INTEGER PRIMARY KEY column is not explicitly given a value, then it will be filled automatically with an unused integer, usually the one more than the largest ROWID currently in use. This is true regardless of whether or not the AUTOINCREMENT keyword is used.

If the AUTOINCREMENT keyword appears after INTEGER PRIMARY KEY, that changes the automatic ROWID assignment algorithm to prevent the reuse of ROWIDs over the lifetime of the database. In other words, the purpose of AUTOINCREMENT is to prevent the reuse of ROWIDs from previously deleted rows.

引用: AutoIncrement SQLite

关于java - 如何在 sqlite 中使用自动增量变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28949689/

相关文章:

java - 如何使用 BufferedInputStream 读取法语字符

java - Java中的ArrayList删除元素

iphone - 如何将数组写入 Objective-C 的 sqlite 数据库?

java - 找到元素并打印大量的一部分

java - 单击 ListView 将 Firebase 数据从一个 Activity 传递到另一个 Activity

java - 为什么操作系统说它有足够的内存时不能分配内存给jvm

android - Android设备电话号码的位置

android - 如何在 Android SQLite 的列中返回唯一行?

android - 读取 Sqlite 数据库时出错 : Database google_app_measurement_local. db not found

python - 调用三个表插入数据。 (sqlite3/python)