Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In java, how can I delete a sqlite table?

I am developing android app. I have to develop a xml button in my activity, and construct my sqlite database and tables. How can I just let user press a button to delete a table? Thanks.

like image 233
user667571 Avatar asked Mar 19 '11 18:03

user667571


People also ask

How do you delete a table in SQLite?

sqlite> DELETE FROM table_name; Following is the basic syntax of DROP TABLE. sqlite> DROP TABLE table_name; If you are using DELETE TABLE command to delete all the records, it is recommended to use VACUUM command to clear unused space.

How do you delete a table in SQLite database explain with an example?

SQLite DELETE Query is used to delete the existing records from a table. You can use WHERE clause with DELETE query to delete the selected rows, otherwise all the records would be deleted.

Can I delete db SQLite?

SQLite saves data to a file. Leverage the methods tailored to the specific OS so you can delete the file. I.E. with Android use the System.

Which method is used to remove records in SQLite?

The TRUNCATE TABLE statement is used to remove all records from a table. SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause.


1 Answers

Hard to answer without more context, but the ultimate sqlite query would be:

db.execSQL("DROP TABLE IF EXISTS table_name");

Where db is a reference to a SqliteDatabase object.

like image 72
Cthos Avatar answered Oct 22 '22 10:10

Cthos