Add a new column to an existing MySeQL table and without overlapping existing table values

I created one database and add several columns to this DB. Now I need some columns added to an existing db with new columns, but not overlapping existing table values.

I have some error for adding new tables with existing table values

+4
source share
3 answers

Use standard SQL in a two-step process to insert new rows and update existing rows. The following is one way to do this, but this is not the best way:

t1 (a, b, c) l.d, l.e, l.f t2 l    t1 r l.d = r.a r.a - ; t1 l    t2 r l.a = r.d   set l.b = r.e, l.c = r.f;

+3

ALTER TABLE onUpgrade()

 @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  //add new coloumn and change your database version to an increased new value
 if (newVersion > oldVersion) {
    db.execSQL("ALTER TABLE TABLE_NAME ADD COLUMN NEW_COLOUMN_NAME TEXT NOT NULL");
    }
}
+1

Try the following query

INSERT INTO new_table (col1, col2, col3 ....) SELECT col1, col2, col3 .... FROM existing_table

+1
source

All Articles