If you want to add a new table to an existing database, then you must do this inside the onUpgrade () method, for example: -
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion == xyz) { db.execSQL(QUERY_CREATE_TABLE_..........NEW); } }
Here xyz is the old version of the database into which you want to add a new table.
And don't forget to increase DATABASE_VERSION
When we increase the database version, then calling the onUpgrade () method and using the condition add the table.
And also create a new table inside onCreate () with existing tables, for fresh installations like: -
@Override public void onCreate(SQLiteDatabase db) { db.execSQL(QUERY_CREATE_TABLE_..........OLD); db.execSQL(QUERY_CREATE_TABLE_..........OLD); db.execSQL(QUERY_CREATE_TABLE_..........NEW); }
source share