【问题标题】:How to delete all tables in SQLite database [duplicate]如何删除SQLite数据库中的所有表[重复]
【发布时间】:2018-10-06 15:45:33
【问题描述】:

我将我的应用程序设计为将登录数据保存在 SQLite 数据库中,但我想在用户从应用程序注销时删除孔表和数据

【问题讨论】:

    标签: java android database sqlite


    【解决方案1】:

    使用 DROP TABLE:

    // query to obtain the names of all tables in your database
    Cursor c = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
    List<String> tables = new ArrayList<>();
    
    // iterate over the result set, adding every table name to a list
    while (c.moveToNext()) {
        tables.add(c.getString(0));
    }
    
    // call DROP TABLE on every table name
    for (String table : tables) {
        String dropQuery = "DROP TABLE IF EXISTS " + table;
        db.execSQL(dropQuery);
    }
    

    希望对你有帮助

    【讨论】:

    • 成功了,谢谢兄弟
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    • 2020-04-18
    • 2012-01-01
    • 2012-11-01
    相关资源
    最近更新 更多