How to delete a database in sqlite?

I am using SQLite in android. I want to delete the database.

For example: mysql- drop database dbname

How to implement this code in SQLite?

+25
android sqlite
Mar 16 2018-11-11T00:
source share
8 answers

The concept of creating or deleting a database does not make sense for an embedded database engine such as SQLite. It only makes sense with a client-server database system such as MySQL or Postgres.

To create a new database, simply execute sqlite_open() or from the sqlite3 databasefilename command line.

To delete the database, delete the file.

Reference: sqlite - unsupported SQL

+25
Mar 16 2018-11-11T00:
source share

To delete the application database, try the following:

  this.deleteDatabase("databasename.db"); 

this will delete the database file

+48
Jun 30 '11 at 11:37
source share

You can abandon tables by issuing the SQL command as usual. If you want to delete the entire database, you will have to delete the file. You can delete the file located in

data/data/com.your.app.name/database/[databasefilename]

you can do this from an eclipse view called “FileBrowser” from the “Android” category, for example. Or directly on the emulator or on the phone.

+6
Mar 16 2018-11-11T00:
source share

If you want to programmatically delete the database, you can use deleteDatabase from the Context class:

deleteDatabase (row name)
Remove the existing private SQLiteDatabase associated with this Context application package.

+5
Sep 05 '11 at 12:28
source share

From http://www.sqlite.org/cvstrac/wiki?p=UnsupportedSql

To create a new database, simply do sqlite_open (). To delete the database, delete the file.

+4
Mar 16 2018-11-11T00:
source share

try the following:

  context.deleteDatabase(DATABASE_NAME); 

How to programmatically delete a SQLite database from Android

+3
Sep 06 '13 at 13:31 on
source share
 SQLite database FAQ: How do I drop a SQLite database? People used to working with other databases are used to having a "drop database" command, but in SQLite there is no similar command. The reason? In SQLite there is no "database server" -- SQLite is an embedded database, and your database is entirely contained in one file. So there is no need for a SQLite drop database command. To "drop" a SQLite database, all you have to do is delete the SQLite database file you were accessing. 

copy from http://alvinalexander.com/android/sqlite-drop-database-how

+2
Jan 10 '14 at 6:52
source share

If you are using SQLiteOpenHelper, you can do it

  String myPath = DB_PATH + DB_NAME; SQLiteDatabase.deleteDatabase(new File(myPath)); 
+2
Jun 21 '15 at 17:47
source share



All Articles