從表中刪除行
刪除表中的所有行
//get writable database
SQLiteDatabase db = openHelper.getWritableDatabase();
db.delete(TABLE_NAME, null, null);
db.close();
從表中刪除所有行,並在返回值中獲取已刪除行的計數
//get writable database
SQLiteDatabase db = openHelper.getWritableDatabase();
int numRowsDeleted = db.delete(TABLE_NAME, String.valueOf(1), null);
db.close();
用 WHERE
條件刪除行
//get writable database
SQLiteDatabase db = openHelper.getWritableDatabase();
String whereClause = KEY_NAME + " = ?";
String[] whereArgs = new String[]{String.valueOf(KEY_VALUE)};
//for multiple condition, join them with AND
//String whereClause = KEY_NAME1 + " = ? AND " + KEY_NAME2 + " = ?";
//String[] whereArgs = new String[]{String.valueOf(KEY_VALUE1), String.valueOf(KEY_VALUE2)};
int numRowsDeleted = db.delete(TABLE_NAME, whereClause, whereArgs);
db.close();