I have a Person
table, each of who's records belongs to a parent record from the Company
table.
One Person
is designated as "Organizer" for their parent Company
. Initially I handled this by having a recursive reference from the Company
table identifying the Person
record that was it's "Organizer" - but the software I'm using to build my application layer falls over - it can't handle recursive references.
I've changed tack, and have added a bit field to the Person
table to identify whether the person is an "Organizer" or not, but neet to ensure that there is only one "Organizer" for each Company
record. If I use an AFTER UPDATE
trigger on the Person table, an update on Person
triggers an update on Person
- obviously I want to avoid recursive triggers.
How can I ensure that there is only ever one Person
marked as the "Organizer" for it's parent Company
?
+-----------+---------+---------+-----------+ +-----------+---------+---------+-----------+
| FirstName | Surname | Company | Organizer | | FirstName | Surname | Company | Organizer |
+-----------+---------+---------+-----------+ +-----------+---------+---------+-----------+
| John | Smith | 1 | True | | John | Smith | 1 | True |
| Mike | Jones | 1 | NULL | | Mike | Jones | 1 | NULL |
| Fred | Green | 1 | NULL | | Fred | Green | 1 | NULL |
| James | McMahon | 2 | NULL | | James | McMahon | 2 | NULL |
| Philip | Stills | 2 | NULL | Making Philip organizer ==> | Philip | Stills | 2 | True |
| Hector | Berlioz | 2 | True | 'triggers' this change ==> | Hector | Berlioz | 2 | NULL |
+-----------+---------+---------+-----------+ +-----------+---------+---------+-----------+