Database Design Example: Competitions and Competitors
In classical relational database design theory, we start with an informal description of the problem, then proceed to create the conceptual model or E/R schema, and finally translate the conceptual model into a logical model. The theoretical part has been addressed in this post. Now let's look at a practical database example, relating to an international championship in which competitors participate in races.
The Conceptual Model
Let's start with the following description of the problem at hand.
Trying to obtain a conceptual model, we immediately identify the entities Competitors and Races. At this point, a fundamental question arises: how to track the scores of each competitor? Each competitor's score cannot be an attribute of Competitors or Races. In fact, in the former case, we would have to duplicate all the competitor's personal information just to assign them a score. In the second case, we would first insert the competitor's attributes into Races and then duplicate all the race information for each competitor to whom we want to assign a score.
A possible modeling solution instead consists of introducing a non-immediately visible entity, the Results entity, which links the competitor's result in that specific race. The E/R model is the one in the figure, which highlights the 1:N associations that link both the instances of the entity Competitors to those of Results, and the instances of Tenders and Results.
The logical model
At this point, applying the rules of derivation, we obtain the so-called logical model, in which we highlight the primary keys and foreign keys.
In particular, primary keys are underlined while foreign keys are indicated with an asterisk.
Competitors(Code, Surname, Name, Day, Month, BirthYear, Nationality)
Races(RaceId, Day, Month, Year, Location, Description, Name)
Results(CodRis, Position, Score, RaceId*, Code*)
To determine the correct data type for each attribute, we can choose the DBMS or application we prefer to create our database. There are many possible choices, ranging from simple applications like Access, to more complex solutions like MySQL, MariaDB, or PostreSQL, where the SQL language can be used directly to create the various tables.