0

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?

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
Roland
  • 826
  • 2
  • 9
  • 24
  • Maybe explain why you believe resetting auto increment in your scenario is required. This breaks database integrity, I would think, so there is probably an alternative solution you should consider. – Colin M. May 07 '14 at 17:53
  • Is this the one you are searching for ? http://stackoverflow.com/questions/5586269/how-can-i-reset-a-autoincrement-sequence-number-in-sqlite – Nidheesh May 07 '14 at 18:04
  • 1
    possible duplicate of [Resetting Autoincrement in Android SQLite](http://stackoverflow.com/questions/9759502/resetting-autoincrement-in-android-sqlite) – CL. May 07 '14 at 18:05

2 Answers2

2

It is possible using this Query

db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + name_of_the_table + "'");
Sainath Patwary karnate
  • 3,165
  • 1
  • 16
  • 18
0

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;
    }