Currently i have a database in android sqllite with many tables of the following column, column A and column B.

目前我在android sqllite中有一个数据库,其中包含以下列的多个表,列A和列B.

Now i am required to have table of column A , column B and column C for subsequent future table created in database. It is alright for me to keep old table of column A and B without changing anything.

现在我需要在数据库中创建后续未来表的列A,列B和列C的表。我可以保留A和B列的旧表而不改变任何东西。

so i have the following concern.

所以我有以下的顾虑。

1 Let say i have the following code

1假设我有以下代码

rssiDB.execSQL("CREATE TABLE IF NOT EXISTS "  + rssiTableName + " (ssid VARCHAR, bssid VARCHAR , rssi INTEGER )" );

What is the meaning of if not exists. If i am trying to create a table with a table name that already exists but different number of column, will the creation of table be successful? What will happen actually.

如果不存在是什么意思。如果我正在尝试创建一个表名已经存在但列数不同的表,那么表的创建是否会成功?实际会发生什么。

for example i have this table of the table name testing20 with column value of a743954759 , -40

例如,我有表名为testing20的表,列值为a743954759,-40

and now i want to create a table of the table name testing20 with column value of peterwifi,a7954759 , -60

现在我想创建一个表名为testing20的表,列值为peterwifi,a7954759,-60

will the above code create a table with the same name but different number of column.

上面的代码将创建一个具有相同名称但列数不同的表。

2 In a database, is it allowed for database to have many table of different column or is it compulsory for database to have every table to have the exact number of column or column name.

2在数据库中,是否允许数据库具有许多不同列的表,或者数据库必须使每个表具有确切的列或列名称数。

Let say i have a database with one table of table name testing1 with column A and column B. can i now add a table with table name testing2 with column A, column B and column C to the database.

假设我有一个数据库,其中包含一个表名为testing1的表,其中包含列A和列B.我现在可以向数据库添加一个表名为testing2的表,其中包含列A,列B和列C.

I know i can try this out to find out myself. However i am afraid that it will affect my existing table if i try it out. Hope someone can answer my question. Thank you

我知道我可以尝试一下找出自己。但是,如果我尝试一下,我担心它会影响我现有的桌子。希望有人能回答我的问题。谢谢

1 个解决方案

#1


0

Table are unique objects in database, so you can define two tables with the same name. But you can alter existing tables and add new columns using ALTER TABLE function on your onUpgrade() method, like this :

表是数据库中的唯一对象,因此您可以定义两个具有相同名称的表。但是您可以在onUpgrade()方法上使用ALTER TABLE函数更改现有表并添加新列,如下所示:

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

Refere to this question How to add new Column to Android SQLite Database? for more info

参考这个问题如何将新列添加到Android SQLite数据库?了解更多信息

更多相关文章

  1. 无法从Android中的Asset文件夹复制数据库
  2. Android之SQLite数据库篇
  3. 如何设计数据库模型来记录客户的历史活动?
  4. 如何使用adb命令查看android中的数据库
  5. Android使用SQLite数据库(3)
  6. viewpager 分页请求数据库并展示
  7. 通过数据库接口获取到的中文数据是问号怎么办?
  8. Android SQLite的数据库文件存储在SD卡中(一)
  9. java 使用jdbc连接Greenplum数据库和Postgresql数据库

随机推荐

  1. java都为我们提供了各种锁,为什么还需要分
  2. Java线程之线程的调度-让步
  3. 常用控件的使用方法(参考书籍'第一行代码'
  4. mysql中的合并表和分区表详解(经常使用的
  5. hive beeline ClassNotFoundException
  6. Redis5.0中的内存淘汰策略详解(最新的版本
  7. Java实现单向链表
  8. 为什么 MongoDB 索引选择B-树,而 Mysql 索
  9. Android实现取消GridView中Item选中时默
  10. 分享Android平板电脑上开发应用程序不能