有没有办法创建没有AUTOINCREMENT列的表?
我已尝试过此链接的解决方案,但它对我不起作用。 prevent autoincrementing integer primary key?
public static final String KEY_ID = "ROW_ID";
public static final String BOOK = "books";
public static final String CAR = "cars";
private static final String BOOK_CAR_TABLE = "BOOK_CAR_Table";
private static final String[] ALL_KEYS = new String[] {KEY_ID, BOOK, CAR};
private static final String BOOK_CAR_CREATE =
"CREATE TABLE " + BOOK_CAR_TABLE + "("+
KEY_ID + " INTEGER PRIMARY KEY," +
BOOK + " TEXT," +
CAR + " TEXT)";
据我所知,当我添加INTEGER PRIMARY KEY时,它会将KEY_ID转换为AUTOINCREMENT列。
public static final String KEY_ID = "ROW_ID";
public static final String BOOK = "books";
public static final String CAR = "cars";
private static final String BOOK_CAR_TABLE = "BOOK_CAR_Table";
private static final String[] ALL_KEYS = new String[] {KEY_ID, BOOK, CAR};
private static final String BOOK_CAR_CREATE =
"CREATE TABLE " + BOOK_CAR_TABLE + "("+
KEY_ID + " INTEGER," +
BOOK + " TEXT," +
CAR + " TEXT)";
AUTOINCREMENT rowid列是由它自己创建的,它是怎么发生的??????
我不想要这个AUTOINCREMENT列。
我该如何防止这种情况?
谢谢
编辑:添加代码
private static final String BOOK_CAR_CREATE =
"CREATE TABLE " + BOOK_CAR_TABLE + "("+
KEY_ID + " INTEGER," +
BOOK + " TEXT," +
CAR + " TEXT) WITHOUT ROWID";
我已经尝试过了,这是强行关闭的。我想这是因为SQLite版本?
答案 0 :(得分:2)
您可以指定WITHOUT ROWID
,但仍需要PRIMARY KEY
。
例如:
CREATE TABLE "table"("key" TEXT PRIMARY KEY, "value" TEXT) WITHOUT ROWID
这需要sqlite 3.8.2或更高版本。问题也标有android-sqlite,因此可能the sqlite version on your Android device更早。