如何将新列添加到Android的SQLite数据库?

问题描述:

我有一个问题,Android的SQLite数据库 我有一个表,它包含一个field.StudentFname 并且该应用程序工作正常与Android 2.3.1,现在如果我添加另一个字段比我的应用程序不工作properly.can任何一个可以帮助我,谁知道数据库的非常好,

i have one problem with android sqlite database i have one table which contains one field.StudentFname and that application is working fine with android 2.3.1 and now if i add another field than my application is not working properly.can any one help me who knows database very well,

您可以使用 ALTER TABLE 功能在 onUpgrade()的方法,像这样的:

you can 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");
    }
}

显然,SQLite的将不同取决于列定义

Obviously, the SQLite will differ depending on the column definition