在我的 Android 应用程序中,我将 SQLite 数据库与 SQLiteOpenHelper
我有几个数据库版本,我一直在通过打开旧数据库版本进行 onUpgrade()
操作,但现在我必须删除其中一个表,因为我不再使用它,我应该做些不同的事情吗?
public void onCreate(SQLiteDatabase database) {
database.execSQL(tableUserCreate);
database.execSQL(tableProductsCreate);
database.execSQL(tablePicturesCreate);
}
public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
switch (version_old) {
case 1:
database.execSQL(addPostcodeFieldToUserTable);
database.execSQL(tablePlacesCreate);
// Intentional fallthrough, no break;
case 2:
database.execSQL(tableProductVideosCreate);
break;
}
} // End of onUpgrade
现在我想在新的数据库版本中删除用户表。我该怎么办?
最佳答案
删除表的SQL:
DROP TABLE table_name
或者使用:
DROP TABLE IF EXISTS table_name
关于删除一张表的 Android SQLite 新 DB 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31626745/