我創建了一個名爲DRINK的表。我最初插入了兩行。升級時,我想刪除兩行並將我的主鍵重置爲1.我得到的行要刪除,但沒有任何運氣重置主鍵。有人知道如何做到這一點的語法,或者甚至有可能嗎?這是從我的onUpdate函數調用的函數:在Android中重置INTEGER PRIMARY KEY AUTOINCREMENT
private void updateMyDatabase(SQLiteDatabase db, int olderVersion, int newVersion){
Log.v("DatabaseHelper","UPDATE MY DATABASE");
if (olderVersion<1){
db.execSQL("CREATE TABLE DRINK (_id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "NAME TEXT, "
+ "DESCRIPTION TEXT, "
+ "IMAGE_RESOURCE_ID INTEGER);");
insertDrink(db,"latte","Espresso and Steamed Milk",R.drawable.latte);
insertDrink(db, "cappuccino", "This a Cappuccino", R.drawable.cap);
}
if (olderVersion < 2){
db.execSQL("delete from DRINK");
db.execSQL("alter table AUTO_INCREMENT =1"); //*** NEED HELP HERE***
insertDrink(db, "coff", "Espresso and Steamed Milk", R.drawable.latte);
}
}
我在網上找到這段代碼,但它不工作。謝謝。
db.execSQL("alter table AUTO_INCREMENT =1");
我得到的序列此日誌錯誤:E/SQLiteLog:(1)在「<」附近:語法錯誤 –
您是否將更改爲所需的值? –
是的,我做到了。下面是確切的代碼行:db.execSQL(「UPDATE SQLITE_SEQUENCE SET seq = <1> WHERE name ='DRINK'」); –