sql - How can I drop a table in a database if another table exists? -


i'm trying drop table in database if table exists.

i made backup of table using query:

alter table appprofile rename appprofile_backup 

now i'd restore backup table , delete appprofile via like:

drop table appprofile if exists table appprofile_backup (alter table appprofile_backup rename appprofile) if not exists appprofile 

however, syntax errors both lines, near "if" token.

for background problem, i'm using sqliteopenhelper class in android. can execute raw sql in environment making call [db_handler_instance].getwritabledatabase().execsql("random query");

what doing in java? can query data dictionary ...

string sql = "select 1 "            + "  sqlite_master  "             + " type = 'table' "            + "   , name = 'appprofile_backup'";  cursor cursor = db.rawquery(sql, null); 

... , drop table, if backup table existing:

if (cursor.movetonext())     db.execsql("drop table appprofile;"); else     db.execsql("alter table ..."); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -