Delete all tables from sqlite database

后端 未结 4 1734
感情败类
感情败类 2020-12-17 10:06

I have done a lot of research and was unable to find a suitable method to delete all the tables in an SQLite database. Finally, I did a code to get all table names from the

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 10:52

    For me, the working solution is:

        Cursor c = db.rawQuery(
                "SELECT name FROM sqlite_master WHERE type IS 'table'" +
                        " AND name NOT IN ('sqlite_master', 'sqlite_sequence')",
                null
        );
        if(c.moveToFirst()){
            do{
                db.execSQL("DROP TABLE " + c.getString(c.getColumnIndex("name")));
            }while(c.moveToNext());
        }
    

提交回复
热议问题