Rename table in sqlite

I am trying to rename a table in my application sqlite. To do this, I use the following command:

ourDatabase.rawQuery("ALTER TABLE " + oldName + " RENAME TO " + newName,
                null);

where oldNameis the old table name, newNameis the new table name, and ourDatabaseis the instance SQLiteDatabase. But that does not work.

What mistake?

Thanks.

+4
source share
2 answers

Try the following:

ALTER TABLE orig_table_name RENAME TO tmp_table_name;
+11
source

Try this code:

    db.beginTransaction();
    try{
        db.execSQL("ALTER TABLE " + oldName + " RENAME TO " + newName+";");
        db.setTransactionSuccessful();
    } finally{
        db.endTransaction();
    }
+7
source

All Articles