gpt4 book ai didi

删除一张表的 Android SQLite 新 DB 版本

转载 作者:太空宇宙 更新时间:2023-11-03 12:50:53 28 4
gpt4 key购买 nike

在我的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com