Roland
Roland

Reputation: 876

How can I reset autoincrement using SqLite in Android?

I have to reset the autoincrement in my database. I can't do the "drop table" and recreate the table.

is there anyway to reset the autoincrement?

Upvotes: 0

Views: 2350

Answers (2)

Kahn Lal Suantak
Kahn Lal Suantak

Reputation: 1

I use this one, maybe it will help

    public boolean deleteAll() {

    SQLiteDatabase db = this.getReadableDatabase();
    db.delete("SQLITE_SEQUENCE","NAME=?",new String[]{TABLE_NAME});
    int affectedRows = db.delete(this.TABLE_NAME, null, null);
    return affectedRows > 1;
    }

Upvotes: 0

Sainath Patwary karnate
Sainath Patwary karnate

Reputation: 3195

It is possible using this Query

db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + name_of_the_table + "'");

Upvotes: 2

Related Questions