I am developing android app. I have to develop a xml button in my activity, and construct my sqlite database and tables. How can I just let user press a button to delete a table? Thanks.
Hard to answer without more context, but the ultimate sqlite query would be:
db.execSQL("DROP TABLE IF EXISTS table_name");
Where db is a reference to a SqliteDatabase object.
There is some ambiguity with your question. Note that there is a difference between DELETING a table and DROPPING a table. Deleting the table simply erases all data from its rows:
database.delete(TABLE_NAME, null, null);
After this, you can still reference the table because it still exists, but creating a new one with the same name may be problematic without using the CREATE TABLE IF NOT EXISTS expression in sql.
Using DROP TABLE completely removes the table and it cannot be referenced again unless it is re-created.
As noted by others, this should work if you want it completely removed from the database:
db.execSQL("DROP TABLE IF EXISTS table_Name");
SQLiteDatabase sdb; sdb=openOrCreateDatabase("dbname.db", Context.MODE_WORLD_WRITEABLE, null); sdb.execSQL("DROP TABLE IF EXISTS tablename");