mardi 22 mars 2016

Deleting two tables with one query in sqlite android with common column and not referenced

I have two tables Class and Students and I want, when Deleting table Class to delete those Students with the same Class id by using something like the following..

public Integer deleteClass (Integer id)
{
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete("Class","_id = ? ",new String[] { Integer.toString(id) });
}

with schema like the following

private static final String CREATE_STUDENTS_TABLE = "CREATE TABLE "
    + STUDENTS_TABLE + "(" + TABLE_STUDENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
    + TABLE_STUDENT_NAME + " TEXT, "
    + TABLE_STUDENT_AGE + " TEXT, "
    + TABLE_STUDENT_CLASS_ID + " INTEGER, "
    + TABLE_STUDENT_AREA + " TEXT" + ")";

private static final String CREATE_CLASS_TABLE = "CREATE TABLE "
    + CLASS_TABLE + "(" + TABLE_CLASS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
    + TABLE_CLASS_NAME + " TEXT, "
    + TABLE_CLASS_CAPACITY + " TEXT, "
    + TABLE_CLASS_POSITION + " TEXT"+ ")";

Aucun commentaire:

Enregistrer un commentaire