0 votes
1 view
in SQL by (6.1k points)

I am facing an issue with the Android SQLite database.

I am having a table which includes one field.StudentFname and that application is working fine with Android 2.3.1 and now if I am adding another field then my application isn't working well.

Can anyone help me with this?

1 Answer

0 votes
by (12.7k points)

You could use ALTER TABLE function on your onUpgrade() method, like this:

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  // If you need to add a column
  if (newVersion > oldVersion) {
     db.execSQL("ALTER TABLE foo ADD COLUMN new_column INTEGER DEFAULT 0");
  }
}

Obviously, the SQLite will be differing depending on the column definition.

Want to be a SQL expert? Come and join this SQL Certification course by Intellipaat.

Related questions

0 votes
1 answer
asked Dec 12, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...