0

I have a sqlite table and I need to keep the ids from changing when I VACUUM the database. The documentation says that VACUUM will not change the rowids of a table that has an explicit INTEGER PRIMARY KEY.

So, I created a table with

CREATE TABLE tableName (
  "rowid" INTEGER PRIMARY KEY, 
  "updated" DATETIME DEFAULT (CURRENT_TIMESTAMP),
  "description" TEXT
)

But that makes a table with two rowid columns. In SQLite Manager add-on for Firefox I see both, and when I try to access the result set in Java it says "ambiguous column: 'rowid'". Is there a way to explicitly create rowid or do I have to use a different name?

4

1 に答える 1

3

rowid は、デフォルトですべての SQLite テーブルの列です

表に単一の列で構成される主キーがあり、その列の宣言された型が大文字と小文字が混在する INTEGER である場合、その列は行 ID の別名になります。

したがって、行 ID 列はデフォルトの行 IDを置き換えません。キーは、デフォルトのROWIDのエイリアスです。

このため、既に使用されているため、列に rowid という名前を付けるべきではありません。既に経験したように、「あいまいな列」エラーが発生します。

ドキュメントには、テーブルに INTEGER PRIMARY KEY が含まれている場合、SQLite が生成している行 ID は変更されないと書かれています。PK は行 ID である必要はありません。

于 2013-08-26T21:37:03.617 に答える