1

how can rename column of table in SQlite database android when upgrade database_version

  @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        if (DATABASE_VERSION == 2) {
           ????
        }

        onCreate(db);
    }

4
  • Possible duplicate of Android Room: How to Migrate Column Renaming? Commented Sep 17, 2019 at 12:50
  • @NicolaGallazzi it is obvious that the OP is not using ROOM. Commented Sep 17, 2019 at 13:00
  • 1
    @forpas, sure thing, my bad! However Room is not the point here, as the SQLite syntax would be the same Commented Sep 17, 2019 at 13:35
  • i dont want migrate and rename table or alter or add column .forexample my column name in last version was a and in new version will be b. i want rename column in onUpgrade method without clear table or clear last version of application Commented Sep 18, 2019 at 18:21

1 Answer 1

2

With ALTER TABLE you can change the column's name (version of SQLite: 3.25.0+):

if (DATABASE_VERSION == 2) {
    db.execSQL("alter table tablename rename columnname to newcolumnname");
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your solution .it means i should renam column dynamically iwith this code?
Replace columnname and newcolumnname with the current and the new name of the column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.