-1

I designed my application to save login data in SQLite database but I want to remove the hole tables and data when the user log out from the application

Ahmed M. Abdalla
  • 1,244
  • 1
  • 11
  • 20

1 Answers1

2

Use DROP TABLE:

// query to obtain the names of all tables in your database
Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
List<String> tables = new ArrayList<>();

// iterate over the result set, adding every table name to a list
while (c.moveToNext()) {
    tables.add(c.getString(0));
}

// call DROP TABLE on every table name
for (String table : tables) {
    String dropQuery = "DROP TABLE IF EXISTS " + table;
    db.execSQL(dropQuery);
}

Hope it will help you

Milad Bahmanabadi
  • 1,047
  • 11
  • 23