0

Currently i have a database in android sqllite with many tables of the following column, column A and column 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.

so i have the following concern.

1 Let say i have the following code

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

and now i want to create a table of the table name testing20 with column value of 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.

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.

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

xiaoxin
  • 7
  • 4
  • There can't be two tables with the same name. How do you expect the interpreter to distinguish between the two tables? – Tah Jan 31 '16 at 08:54

1 Answers1

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 :

 @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

Community
  • 1
  • 1
Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57