I have 3 table in helper
1)Login_Table table for user information Storing 2)Service_Table for Storing services having one column references to Login_Table table 3)SubService_Table for Storing sub services having one column references to service_table and another Login_Table table
i want to delete row from particular service table then automatic delete record from the subservice row which reference to service table id table but when i delete particular row from service table it force to be close
db.execSQL( " CREATE TABLE "+ LoginTable +" ( " +login_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " + NAME + " TEXT, " + USERNAME + " TEXT, " +PASSWORD + " TEXT," + GENDER + " TEXT, " + CONTACT + " TEXT, " + SQUE + " TEXT, " + ANSWER + " TEXT, " + EmailId + " TEXT, " + UType+" TEXT)");
db.execSQL("CREATE TABLE "+Services+"("+Ser_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+Ser_Name+" TEXT, "+Ser_UID+" Integer not null, FOREIGN KEY ("+Ser_UID+") REFERENCES "+LoginTable+" ("+login_ID+"));");
db.execSQL("CREATE TABLE "+Sub_Services+"("+Sub_Ser_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+Sub_Ser_Name+" TEXT, "+Ref_Ser_ID+" Integer not null, "+Sub_Ser_UID+" Integer not null, FOREIGN KEY ("+Ref_Ser_ID+") REFERENCES "+Services+" ("+Ser_ID+") ON DELETE CASCADE , FOREIGN KEY ("+Sub_Ser_UID+") REFERENCES "+LoginTable+" ("+login_ID+")) ;");
i also used enable foreign key by following code
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
How cascade delete exactly use in android SQLite?? i used android 4.2 and version of sqlite 3.7.11...