我需要使用相同的ID删除两个表。到目前为止,我正在使用这种方法:
public Integer deleteSplitMondayByID (String ID){
SQLiteDatabase database = this.getWritableDatabase();
return database.delete(TABLE_NAME, "ID = ?", new String[]{ID});
}
如何在其中添加一张桌子?我已经尝试过
(TABLE_NAME, TABLE_NAME2 "ID = ?", new String[]{ID})
(TABLE_NAME + " , " + TABLE_NAME2 "ID = ?", new String[]{ID})
(TABLE_NAME + " UNION " + TABLE_NAME2 "ID = ?", new String[]{ID})
但是我无法删除它们。那么,我该怎么做呢?
答案 0 :(得分:1)
如上所述,您不能在一个语句中从两个表中删除,尤其是在Java库中抽象该表时。尝试这样的事情:
public Integer deleteSplitMondayByID (String ID){
int delcount = 0;
SQLiteDatabase database = this.getWritableDatabase();
database.beginTransaction();
try
{
delcount += database.delete(TABLE_NAME, "ID = ?", new String[]{ID});
delcount += database.delete(TABLE_NAME2, "ID = ?", new String[]{ID});
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
return delcount;
}