[ACCEPTED]-In java, how can I delete a sqlite table?-sqlite

Accepted answer
Score: 41

Hard to answer without more context, but 2 the ultimate sqlite query would be:

db.execSQL("DROP TABLE IF EXISTS table_name");

Where 1 db is a reference to a SqliteDatabase object.

Score: 18

There is some ambiguity with your question. Note 11 that there is a difference between DELETING a table 10 and DROPPING a table. Deleting the table simply 9 erases all data from its rows:

database.delete(TABLE_NAME, null, null);

After this, you 8 can still reference the table because it 7 still exists, but creating a new one with 6 the same name may be problematic without 5 using the CREATE TABLE IF NOT EXISTS expression in sql.

Using DROP TABLE completely 4 removes the table and it cannot be referenced 3 again unless it is re-created.

As noted by 2 others, this should work if you want it 1 completely removed from the database:

db.execSQL("DROP TABLE IF EXISTS table_Name");
Score: 0
SQLiteDatabase sdb;
sdb=openOrCreateDatabase("dbname.db", Context.MODE_WORLD_WRITEABLE, null);
sdb.execSQL("DROP TABLE IF EXISTS tablename");


Score: 0

As a Singleton method

 // todo DELETE a special field(s)
public boolean deleteFromTable(int yurtId) {
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    final String whereClause = DBHelper.COLUMN_Y_YURT_ID + " =?";
    final String whereArgs[] = {String.valueOf(yurtId)};
    int affectedRows = database.delete(DBHelper.TABLE_NAME_YEMEKCI, whereClause, whereArgs);
    return affectedRows > 0;

  // todo DELETE all table 
public boolean deleteTable() {
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    int affectedRows = database.delete(DBHelper.TABLE_NAME_YEMEKCI, null, null);
    return affectedRows > 0;


More Related questions