删除表中的所有行
//获取可写数据库 SQLiteDatabase db = openHelper.getWritableDatabase(); db.delete(TABLE_NAME, null, null); db.close();
要删除表中的所有行并获取返回值中已删除行的计数
//获取可写数据库 SQLiteDatabase db = openHelper.getWritableDatabase(); int numRowsDeleted = db.delete(TABLE_NAME, String.valueOf(1), null); db.close();
要删除row(s)与WHERE条件
//获取可写数据库 SQLiteDatabase db = openHelper.getWritableDatabase(); String whereClause = KEY_NAME + " = ?"; String[] whereArgs = new String[]{String.valueOf(KEY_VALUE)}; //对于多个条件,请使用AND将它们加入 //String whereClause = KEY_NAME1 + " = ? AND " + KEY_NAME2 + " = ?"; //String []其中,Args =新的String [] {String.valueOf(KEY_VALUE1),String.valueOf(KEY_VALUE2)}; int numRowsDeleted = db.delete(TABLE_NAME, whereClause, whereArgs); db.close();