I have two tables. Club and Coach. Between them is 0,1 - 0,1 relationship (coach can have zero or one club. club can have zero or one coach). When I want to change the coach of the given club, i have to update the club table. So i have to change idCoach of that club. Lets consider a new coach (the newly assigned coach of the given club) is already a coach of some other club. I have to set to Null field idCoach of that club, because his coach will be assigned to another club. Also if the club for which I want to change the coach, already has a coach, then I have to set idClub of that coach (in Coach table) to Null.
All the given above, also applies to when I want to change the club of the certain coach. (have to set to Null idCoach field of the previous club of a given coach and have to set to null idCoach of the new club) .
The same problems could occur when I insert new record in Club or Coach table, or if I delete the existing (in insert, update and delete I have to watch out for the corresponding references and unlink them).
I want to solve this with triggers. I guess I would have to have 3 triggers in Club table (for insert, update and delete) and 3 more in Coach table.
In update trigger (for example in Club) I have to update Coach table which will again trigger update in Club (cause in it's body it has to update Club table) and that trigger will update Coach and trigger and so forth. So I'll have a dead lock.
How to solve this?
This is the first time ever I work with triggers, so sorry in advance, for this big explanation of a simple thing.
Cheers!