I want my users to be able to reset the application, then I need to reset the SQLite database that I have created. How can I do that? I want to reset the database or delete and recreate the database.
Asked
Active
Viewed 5.2k times
24
-
don't delete entire instead clear all tables data from database. – Vijju Jan 30 '14 at 13:44
6 Answers
16
Just delete your database by
context.deleteDatabase(DATABASE_NAME);
Please make sure to close your database before deleting.

Linga
- 10,379
- 10
- 52
- 104
-
I tryed delet database. The problem is that when I do this, I cant insert anything again. – Roland Jan 30 '14 at 13:12
-
After delete, call the create database script at`onCreate` of the opening activity – Linga Jan 30 '14 at 13:13
-
6
3
Working for me.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS TABLE_NAME");
onCreate(db);
}

user3307005
- 216
- 4
- 12
1
You can delete the content of all your tables using delete from table where 1=1
, or you can call your database onCreate
method again

Giacomoni
- 1,468
- 13
- 18
-
Calling onCreate worked for me. I passed getWritableDatabase() from my SqlLiteOpenHelper sublass as the onCreate parameter btw. – Shane Sepac Aug 29 '17 at 22:35
0
There are two option to clear the table from the database
Firstly
If you wan to delete the data on specific row you need to add this code in the database class
public Boolean specification(int id, String table_name)
{
return db.delete(table_name, KEY_ID + "=" + id, null) > 0;
}
and add the below code when you want to perform this action
db.deleteSpecificOrder(id, "table_orders");
Secondly
If you want to delete all the data from th table then you just need to add below code into your database
public void clearDatabase(String TABLE_NAME) {
db = this.getReadableDatabase();
String clearDBQuery = "DELETE FROM " + TABLE_NAME;
db.execSQL(clearDBQuery);
}
and then add the below line where you want to perform that action
db.clearDatabase("table_food_items");
I Hope that will help you

Muhammad Yaseen
- 278
- 2
- 12