how to drop database in sqlite?

前端 未结 8 1114
终归单人心
终归单人心 2020-12-03 17:05

I\'m using SQLite in android. I want to drop the database.

For example: mysql- drop database dbname

How do I implement this code in SQLite?

相关标签:
8条回答
  • 2020-12-03 17:19
    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

    0 讨论(0)
  • 2020-12-03 17:22

    to delete your app database try this:

     this.deleteDatabase("databasename.db");
    

    this will delete the database file

    0 讨论(0)
  • 2020-12-03 17:23

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

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

    0 讨论(0)
  • 2020-12-03 17:27

    If you use SQLiteOpenHelper you can do this

            String myPath = DB_PATH + DB_NAME;
            SQLiteDatabase.deleteDatabase(new File(myPath));
    
    0 讨论(0)
  • 2020-12-03 17:30

    try this :

     context.deleteDatabase(DATABASE_NAME);
    

    How to delete SQLite database from Android programmatically

    0 讨论(0)
  • 2020-12-03 17:32

    You can drop tables by issuing an SQL Command as you would normally. If you want to drop the whole database you'll have to delete the file. You can delete the file located under

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

    you can do this from the eclipse view called "FileBrowser" out of the "Android" Category for example. Or directly on your emulator or phone.

    0 讨论(0)
提交回复
热议问题