从表中删除行
删除表中的所有行
//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();