Consider the following two tables:
User
- UserID
- UserName
Group
- GroupID
- GroupName
The obvious association is that Users will be in Groups. This by itself is a simple many-to-many join situation, so lets add a 3rd table:
UserGroup
- UserID
- GroupID
Under this textbook schema, I can easily include a specific User in a specific Group by INSERTing a new record into the UserGroup table. Before going any further I want to point out that I recognize this as the optimal situation in database design.
However, I want to also be able to make Groups that include all Users by default unless they are specifically excluded somehow. Logically, I've broken this down into two "modes" for which a Group must be in one or the other:
- Include Mode: Every User is excluded unless specifically included.
- Exclude Mode: Every User is included unless specifically excluded.
So what is the best way to design such a relationship? You can add columns, add tables, and have fancy join conditions and WHERE constraints. No triggers or s'procs, please.