2011-03-16 213 views

回答

27

創建或刪除數據庫的概念對於像SQLite這樣的嵌入式數據庫引擎沒有意義。它只與客戶端服務器數據庫系統有關,比如MySQL或Postgres使用的數據庫系統。

要創建新數據庫,只需執行sqlite_open()或從命令行sqlite3 databasefilename

要刪除數據庫,請刪除該文件。

參考:sqlite - Unsupported SQL

6

可以通過發出SQL命令,你通常會下降tables。如果你想刪除整個數據庫,你必須刪除文件。您可以刪除所在的文件下

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

你可以從所謂的「FileBrowser」出例如「Android」的範疇的Eclipse視圖做到這一點。或直接在您的模擬器或手機上。

49

刪除您的應用程序的數據庫試試這個:

this.deleteDatabase("databasename.db"); 

這將刪除數據庫文件

+4

您必須有權訪問上下文才能執行此操作。 – 2012-07-01 12:40:09

+0

+1的答案...我只是想降級數據庫,這是不允許的,所以我不得不刪除數據庫... :) – 2014-09-08 15:00:14

+0

我知道這有點晚,但它可以降級你的數據庫。它只是默認禁用。你需要自己實現它。 – 2017-02-19 01:03:20

5

如果你想刪除的數據庫編程,你可以使用deleteDatabaseContext類:

deleteDatabase(String name)
Delete an existencein g與此Context的應用程序包關聯的私有SQLiteDatabase。

2
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. 

副本從http://alvinalexander.com/android/sqlite-drop-database-how

2

如果使用SQLiteOpenHelper你可以做到這一點

 String myPath = DB_PATH + DB_NAME; 
     SQLiteDatabase.deleteDatabase(new File(myPath));