I want to know if it is a good idea to use ON DELETE CASCADE for example below. This is so I have a general idea when to use ON DELETE CASCADE to delete rows .
Module Table:
ModuleId (PK) ModuleNo ModuleName
11 CHI2333 ICT
Course_Module Table:
CourseId ModuleId (FK)
3 11
Session Table (Exams):
SessionId SessionName ModuleId (FK)
5 ASDEE 11
In example above, if I delete a row from the Module Table, then it will delete rows in the other 2 tables which contains the same ModuleId. In the Course_Module Table it determines which course contains which Modules and in the Session Table which holds exam details, it will delete any rows (exams) where it contains the deleted ModuleId.
Is it ok to do this for the example above and my general question is that is it wise and normal practice to use ON DELETE CASCADE to delete foreign key rows when the row from the parent table is deleted or remove?
Personally I think its better to have that logic in your code rather than relying on the DB to do the work for you. This is the way I code all my apps.
Just my 2 cents.