Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite new DB version with one table removed

In my Android application I'm using the SQLite DB with SQLiteOpenHelper

I have several DB versions, and I've been doing onUpgrade() operations by switching on the old db version, but now I have to remove one of the tables because I'm no longer using it, so should I do something different?

public void onCreate(SQLiteDatabase database) {
        database.execSQL(tableUserCreate);
        database.execSQL(tableProductsCreate);
        database.execSQL(tablePicturesCreate);
    }


public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
    switch (version_old) {
    case 1:
        database.execSQL(addPostcodeFieldToUserTable);
        database.execSQL(tablePlacesCreate);
        // Intentional fallthrough, no break;
    case 2:
        database.execSQL(tableProductVideosCreate);
        break;
    }
} // End of onUpgrade

Now I want to remove the User table in a new DB version. What do I do?

like image 272
Kaloyan Roussev Avatar asked Dec 01 '25 00:12

Kaloyan Roussev


1 Answers

SQL for dropping a table:

DROP TABLE table_name

Or use:

DROP TABLE IF EXISTS table_name
like image 74
Roberto Anić Banić Avatar answered Dec 03 '25 12:12

Roberto Anić Banić



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!