【发布时间】:2011-03-16 14:43:38
【问题描述】:
我在安卓中使用 SQLite。我想删除数据库。
例如:mysql- drop database dbname
如何在 SQLite 中实现此代码?
【问题讨论】:
我在安卓中使用 SQLite。我想删除数据库。
例如:mysql- drop database dbname
如何在 SQLite 中实现此代码?
【问题讨论】:
要删除您的应用数据库,请尝试以下操作:
this.deleteDatabase("databasename.db");
这将删除数据库文件
【讨论】:
创建或删除数据库的概念对于像 SQLite 这样的嵌入式数据库引擎没有意义。它只对客户端-服务器数据库系统有意义,例如 MySQL 或 Postgres 使用的。
要创建一个新数据库,只需执行sqlite_open() 或从命令行sqlite3 databasefilename。
要删除数据库,请删除文件。
【讨论】:
您可以像往常一样通过发出 SQL 命令来删除 tables。如果要删除整个数据库,则必须删除该文件。您可以删除位于
data/data/com.your.app.name/database/[databasefilename]
例如,您可以从“Android”类别中名为“FileBrowser”的 Eclipse 视图中执行此操作。或直接在您的模拟器或手机上。
【讨论】:
试试这个:
context.deleteDatabase(DATABASE_NAME);
【讨论】:
来自http://www.sqlite.org/cvstrac/wiki?p=UnsupportedSql
要创建一个新数据库,只需执行 sqlite_open()。要删除数据库, 删除文件。
【讨论】:
如果您想以编程方式删除数据库,您可以使用 deleteDatabase from Context 类:
删除数据库(字符串名称)
删除与此上下文的应用程序包关联的现有私有 SQLiteDatabase。
【讨论】:
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复制
【讨论】:
如果你使用 SQLiteOpenHelper 你可以这样做
String myPath = DB_PATH + DB_NAME;
SQLiteDatabase.deleteDatabase(new File(myPath));
【讨论】: