Quote:
|
Originally Posted by mike_bike_kite
I think I'd tend to go the other way and have a more generic table for People, Cases and Groups. I'd have a common id field and just use a type field to specify what type of entity it is. I'd use a Relationship table to say what people belong in what cases and groups. My reasoning is : - All notes, meetings and memos link with a single table
- The resulting code would be simpler
- The above also means FKs can be used (if that's important to you)
|
It most certainly is important to me to use FKs!
Quote:
|
Originally Posted by mike_bike_kite
- You have the option of having groups being made up of other groups etc
This type of design would mean roughly 5 tables which is simpler still  Just my 2c.
|
I'm wary of generic tables like that - they tend to require columns that apply to one type and not another (e.g. first_name), lots of NULLs, and so on. Then you find that process X applies to one type and not another; type A can have related Zs, but type B can't; etc. etc. That's partly why I was leaning towards the supertype-subtype approach, but then Stéphane Faroult (The Art of SQL) got me concerned about what this might lead to:
Quote:
|
You can use subtypes incorrectly. As one of the reviewers remarked, having a kind of super-generic parent table that is referred to several times in the most innocuous query isn't a model for efficiency. Such a super-generic parent table is hammered by all queries if it stores vital information. Subtypes must be born of logical distinction, not of an ill-conceived desire to implement with tables a strong inheritance scheme inspired from object-oriented techniques.
|
Quote:
|
Originally Posted by mike_bike_kite
What's the difference between cases and groups?
|
That's an interesting point that I hadn't considered - it would appear to be "obvious" what the difference is in the real world system that's being modelled, but perhaps they could be put together and distinguished by their type.
(Please bear with me...) So far I've come up with five ways of modelling this:
1. People, Cases, and Groups are all related to one Notes table, which has three foreign key fields (person_id, etc.). For: simple structure. Against: Needs NULLs and constraints to ensure only one FK in Notes is filled; many queries effectively require case statements. This was the first model I discarded because I believe that over time that kind of structure creates more and more headaches...
2. People, Cases, and Groups relate to separate Person_notes, Case_notes, and Group_notes tables (as per Rudy's suggestion above). For: fairly easy to work with (I think the most complicated queries require UNIONs); FK constraints. Against: repeated structure; similar data (notes) in several tables; does not capture similar behaviour of the three main entities (and any common behaviour added in future requires more repeated structures).
3. People, Cases, and Groups are all subtype tables related to a supertype Entities table, which in turn relates to Notes (which has entity_id as FK). For: FKs; reduces repetition. Against: adds another layer of abstraction; complicates queries; are they really subtypes?
4. People, Cases, and Groups have their own join tables (People_notes, etc.) to a single Notes table. For: note data resides in a single table. Is this really just a special case of #2? It might avoid UNIONs for queries that require data from the various note types, but would probably require LEFT OUTER JOINs from Notes instead.
5. Notes is a supertype of Person_notes, Case_notes, and Group_notes, which relate to People, Cases, and Notes respectively. In practice this is probably just a restatement of #4.
Sorry to go on at length about this, but it seems to be an example of a situation that wouldn't be too uncommon yet doesn't seem to be very well covered in whatever I've read. I am very interested to see what people think about the various possibilities and am hoping it will be instructive (not just for me!). I think my main issue is that I (still) don't have enough experience to know whether going with model X above will lead to complication Y in circumstance Z.