I'm trying to drop a table in a database if another table exists.
I made a backup of a table using this query:
ALTER TABLE AppProfile RENAME TO AppProfile_backup
Now I'd like to restore the backup table and delete AppProfile via something like:
DROP TABLE AppProfile IF EXISTS TABLE AppProfile_backup
(ALTER TABLE AppProfile_backup RENAME TO AppProfile) IF NOT EXISTS AppProfile
However, I get syntax errors for both lines, near the "IF" token.
For background about this problem, I'm using the SQLiteOpenHelper class in Android. You can execute raw SQL in that environment by making the call [db_handler_instance].getWritableDatabase().execSQL("random query");
AppProfilehas to be changed; in particular, if columns have to be deleted. Adding and checking for columns is possible (usingpragma table_info(<table_name>)). So it depends ... ;)