为什么SQLite数据库rowid由它自己创建? Android的

时间:2014-09-29 16:41:36

标签: mysql database sqlite android-sqlite auto-increment

有没有办法创建没有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版本?

1 个答案:

答案 0 :(得分:2)

您可以指定WITHOUT ROWID,但仍需要PRIMARY KEY

例如:

CREATE TABLE "table"("key" TEXT PRIMARY KEY, "value" TEXT) WITHOUT ROWID

这需要sqlite 3.8.2或更高版本。问题也标有,因此可能the sqlite version on your Android device更早。

进一步阅读:http://www.sqlite.org/withoutrowid.html