An app I'm currently designing allows users to create custom competitive leagues (think of it kind of like fantasy sports) and each user can join different leagues and each league consists of multiple rounds where the users (hereafter referred to as Players) will compete and can earn points for different criteria/accomplishments established for each league. Here's some key info to note:
- Points are accrued across all the rounds during a league/season
- The custom point criteria/weight settings can change across each round. I’m thinking that for the most part these round-by-round point settings will stay relatively consistent during the span of a league (i.e. season) but a league could certainly choose switch it up a lot. With the way I currently have things setup, the league will establish a group of default league-level point settings that will be the default for each round but they can always decide to either update the point weights, add new point settings or deactivate/activate them. Because of these sub-settings that could vary from round-to-round, should I have one table for the default league-level point setting and then another for round-level sub-settings that will include all of the settings actually implemented for each round?
- Similar to the above, each round can consist of different players; it’s not necessarily going to be all the league members/players or the same group of players in each round so I currently have one table for league player and one for round player and then a table that tracks the points earned for each player that basically has foreign keys linking to a bunch of other tables, which seems a little weird to me.
Does this approach make sense or am I overthinking or missing something? Below is a link to an image of an entity relationship diagram that I’ve concocted and it just feels a little wonky to me, especially with the Point Earned table, but that may just be due to my lack of experience with designing relational databases. Note that the fields listed with ‘CPK’ are composite primary keys that consist of the concatenation of the corresponding foreign keys in that table. Any and all feedback is welcome, thanks!
Confirmation
Yes. What you are implicitly declaring is, a round has one setting, which is:
That is a typical OR Gate in Logic, and there is a correct method to implement that in a RElational database: an Exclusive Subtype.
That is correct: they are two discrete Facts, the latter is Dependent on the former. That means:
Your data model goes off the rails at that point.
Problem
Evidently, you have learned the value of data integrity. Eg. you are attempting to ensure that a player in a round in a league is actually a player who is registered in that league; etc. Excellent. You are trying to achieve Relational Integrity, which is logical (and distinct from Referential Integrity, which is a physical feature of SQL).
The second problem, however, is that you don't have keys, you have physical
Record IDs
... declared as "keys". Therefore the logical thing (data is logical) that you are trying to constrain isn't constrained. And that effort, that attempt, results in scores of relationships ... that do not achieve the desired result.Relational Key
Record ID
.You are using
Record IDs
declared as "keys" (that will confuse the hell out of you, because it is not a Key, and it has none of the properties of a Key). And then trying to get some Relational Integrity (which you intuitively know only the Relational Model provides) through Composite Keys ... but you are using the declared Non-Keys, so it fails, and makes a complex model in the attempt.Record IDs
Also, your
CPK
is a great attempt to overcome the limitations of the "theoreticians", but it does not specify precisely what columns make it up. That is easily corrected if you use IDEF1X (the standard for modelling Relational data): the columns that make up the Key, Primary or Alternate, are explicit.The next problem is, your logical rows (as distinct from physical records) are not unique, and the RM demands that logical rows are unique.
User
,username
is not uniqueusername
is actually the logical Key (which would make the rows unique)(first_name, last_name)
, which is a second logical Keyuser_id
is 100% useless (achieves nothing, it is merely an additional column and an additional index, which is to be avoided)username
is the real, logical,PRIMARY KEY
, which is migrated asFOREIGN KEY
wherever it is referenced.Likewise, you can get rid of all the
Record IDs
.Relational Data Model
You have been schooled in the physical (falsely named "relational"), and you have tried to 'move up' into the logical. Great idea, but that does not work. The logical comes first, and when ready, one 'moves down' into the physical. The physical serves the logical, not the reverse.
Try this.
Note • Notation
All my data models are rendered in IDEF1X, the Standard for modelling Relational databases since 1993
My IDEF1X Introduction is essential reading for beginners
The IDEF1X Anatomy is a refresher for those who have lapsed.
Note • Content
Relational Key
round_player
must be registered in theleague
that theround
is inround_default_weight
must be one of the validleague_weights
that have been set up for theleague
that theround
is inExclusive Subtype
round
has either oneround_default_weight
xor oneround_custom_weight
I do not understand what you mean precisely by
point_setting
. I understand it to be a weight that is applied to the score, which is modelled.I do not understand why you have
Point Earned
as a separate file (ie. separate to the issue of multiple parents). That appears to be one record per point scored. Assuming that only players can score points, you can instead accumulate points into theround_player
row.Your design allows multiple admins per
league
, not one. Please confirm.Enjoy. Please feel free to ask specific questions. There may be clarifications: when identified, I will issue a progressed data model.
Comments
Yes.
Ok. Try this.
There is no need to maintain one row per
round_player
perround
perpoint
. We can maintain a row perpoint_type
containing total points perpoint_type
instead.You need to specify the
point_types
(I have given rugby point types as an example).It is a normal table, not a Reference or "look-up" table, because the relation is Identifying.