Take the 2-minute tour ×

In my application, I want to delete my existing database and create a new one with default values. Default values can be inserted to the database from XML.

Does anyone have any idea on how to reuse a database?

share|improve this question
add comment

2 Answers

Assuming that you are using a SQLite database, to delete all the rows from all of your tables inside your database you can use db.execSQL() and heed the advice from this question Drop all tables command:

You can do it with the following DANGEROUS commands:

 PRAGMA writable_schema = 1;
 delete from sqlite_master where type = 'table';
 PRAGMA writable_schema = 0;

you then want to recover the deleted space with


and a good test to make sure everything is ok


If you haven't written a way to read your XML data yet, this is excellent reading: Store parsed xml data to sqlite ? Android

share|improve this answer
add comment

Well basically that's not an Android specific question.

Firstly when do you want to recreate the database with default values and how to trigget it.

  • In an UI event like button click etc?
  • Or when you start/stop or destroy your activity?

In any cases you need to drop the database and recreate the whole structure (tables,relationships etc.) again.

share|improve this answer
add comment

Your Answer


