I am trying to rename a table in my app's sqlite database. For that I am using the following command:
ourDatabase.rawQuery("ALTER TABLE " + oldName + " RENAME TO " + newName,
null);
where oldName is old name of the table, newName is the new name of table and ourDatabase is an instance of SQLiteDatabase. But this is not working.
What's the mistake ?
Thanks.
Summary. Use the ALTER TABLE statement to modify the structure of an existing table. Use ALTER TABLE table_name RENAME TO new_name statement to rename a table. Use ALTER TABLE table_name ADD COLUMN column_definition statement to add a column to a table.
The rename table option allows the user to type in a new name for the table being renamed. The tool then generates and can execute the SQL to rename the SQLite database table.
Introduction to SQLite UPDATE statement In this syntax: First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause.
Try execSQL instead of rawQuery like:
ourDatabase.execSQL("ALTER TABLE " + original_table_name + " RENAME TO " + new_table_name);
Try this code:
db.beginTransaction();
try{
db.execSQL("ALTER TABLE " + oldName + " RENAME TO " + newName+";");
db.setTransactionSuccessful();
} finally{
db.endTransaction();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With