Relational model and normalisation (1NF to 3NF)
An ER model becomes tables: every entity type becomes a relation, a 1:n relationship becomes a foreign key on the n side, and an m:n relationship becomes its own junction table. Normalising up to third normal form removes redundancy and with it insertion, update and deletion anomalies.
Your goal: You can convert an ER model into a relational model with primary and foreign keys, spot anomalies in a table and bring a table step by step into first, second and third normal form.
Helpful first: ER model: entities, relationships, cardinalities
From ER model to table
In the relational model (Relationenmodell) a database consists only of tables (relations). Each row is a record (tuple), each column an attribute. You write a relation briefly as a relation schema: the name, then the attributes in brackets. In exams the primary key is usually underlined; here it is in bold. A foreign key (Fremdschlüssel) gets an arrow ↑.
A foreign key is an attribute whose values refer to the primary key of another table. This is how the links between tables are made.
| in the ER model | in the relational model |
|---|---|
| entity type | its own table, the primary key stays |
| 1:n relationship | foreign key in the table on the n side |
| 1:1 relationship | foreign key in one of the two tables, usually on the side that takes part optionally |
| m:n relationship | its own junction table (Zwischentabelle) with both foreign keys; together they form the primary key; relationship attributes are added |
Example, an invented tea shop: KUNDE (KundenNr, Name, PLZ, Ort), BESTELLUNG (BestellNr, Datum, ↑KundenNr), TEESORTE (ArtikelNr, Bezeichnung, Preis), ENTHAELT (↑BestellNr, ↑ArtikelNr, Menge). The table and attribute names stay German, as in a German exam (Kunde = customer, Bestellung = order, Menge = quantity).
Why the foreign key belongs on the n side: an order has exactly one customer, so exactly one value fits there. On the customer side you would have to write a list of many order numbers into one cell – and first normal form already forbids that.
Redundancy and anomalies
Redundancy means the same information is stored several times in the database. That costs storage, but above all it leads to anomalies, i.e. errors when the data are changed. Look at this invented table:
| BestellNr | KundenNr | Name | Ort | ArtikelNr | Bezeichnung | Menge |
|---|---|---|---|---|---|---|
| 501 | 17 | Okafor | Ahornstadt | 210 | Stumpenkerze | 4 |
| 501 | 17 | Okafor | Ahornstadt | 315 | Teelichtset | 2 |
| 502 | 23 | Lindqvist | Birkenau-Süd | 210 | Stumpenkerze | 1 |
- Update anomaly (Änderungsanomalie): if Ms Okafor moves, you must change her town in every one of her rows. If you forget one, the data contradict each other.
- Insertion anomaly (Einfügeanomalie): you cannot store a new item that has never been ordered, because without an order the key would be incomplete.
- Deletion anomaly (Löschanomalie): if you delete order 502, everything you knew about customer Lindqvist disappears with it.
The cure is always the same: every fact should be stored in exactly one place. To achieve this, you split the table into several tables linked by foreign keys. The normal forms tell you how.
First normal form: atomic values only
A relation is in first normal form (1NF) if every attribute contains only atomic (indivisible) values and there are no repeating groups.
You spot violations by cells containing lists (210 Stumpenkerze, 315 Teelichtset), by combined values that are needed separately (Okafor, Ahornstadt in one column), or by groups of columns such as Artikel1, Artikel2, Artikel3.
Here is how you proceed:
- Split combined values into separate columns (Name, PLZ, Ort; ArtikelNr, Bezeichnung).
- Break up lists: one row for each list element, the other values are copied.
- Determine the primary key again. After breaking up the list, BestellNr is often no longer enough; the key becomes composite, e.g. (BestellNr, ArtikelNr).
1NF at first even increases redundancy. That is fine: only now can you see clearly the dependencies that you remove in the next steps.
Second and third normal form: removing dependencies
An attribute B is functionally dependent on A (A → B) if exactly one value of B belongs to each value of A. Example: ArtikelNr → Bezeichnung.
Second normal form (2NF): the relation is in 1NF, and every non-key attribute depends on the whole primary key, not just on part of it. The problem can only arise with a composite key. Test question for each attribute: is part of the key already enough to fix the value?
- Menge depends on (BestellNr, ArtikelNr) – fully dependent, it stays.
- Bezeichnung depends only on ArtikelNr – partial, it is moved out into ARTIKEL.
- Datum, KundenNr, Name, Ort depend only on BestellNr – moved out into BESTELLUNG.
Third normal form (3NF): the relation is in 2NF, and no non-key attribute depends transitively on the key, i.e. via another non-key attribute. In BESTELLUNG (BestellNr, Datum, KundenNr, Name, Ort) we have BestellNr → KundenNr → Name, Ort. Name and Ort describe the customer, not the order. They move to KUNDE; only ↑KundenNr stays in BESTELLUNG.
Memory aid: every non-key attribute depends on the key (1NF), on the whole key (2NF) and on nothing but the key (3NF).
Whether PLZ → Ort (postcode → town) holds depends on the case description: if in the case every postcode determines exactly one town, this is a transitive dependency too, and you can create a table ORT (PLZ, Ort). In practice this is often left out on purpose; in the Abitur you state your assumption.
Referential integrity
Referential integrity (referentielle Integrität) means every foreign key value refers to a record that really exists (or is empty, if that is allowed). The database system enforces this as soon as you declare the foreign key as such.
| Action | possible violation |
|---|---|
| Inserting into BESTELLUNG | KundenNr 99 does not exist in KUNDE – the system rejects it. |
| Deleting in KUNDE | Customer 17 still has orders – they would point to nothing. |
| Changing the primary key in KUNDE | The orders still refer to the old number. |
For deleting a record that is still referred to, there are three usual rules: the deletion is refused (the default), the dependent records are deleted as well (cascading delete), or the foreign key is set to empty. Which one fits is a business decision: deleting orders as well would mean destroying documents the company has to keep.
Worked example
The invented candle maker Wachswerk Talblick keeps its orders in a single list:
| BestellNr | Datum | Kunde | Artikel |
|---|---|---|---|
| 501 | 03.02. | 17, Okafor, Ahornstadt | 210 Stumpenkerze ×4; 315 Teelichtset ×2 |
| 502 | 05.02. | 23, Lindqvist, Birkenau-Süd | 210 Stumpenkerze ×1 |
Each item has a fixed description and a price. Bring the data step by step into third normal form and state the foreign keys.
- 1NF: Kunde is split into KundenNr, Name, Ort, Artikel into ArtikelNr, Bezeichnung, Menge (Preis is added as an attribute of the item). The item list is broken up: order 501 gets two rows. The key is now (BestellNr, ArtikelNr): LISTE (BestellNr, ArtikelNr, Datum, KundenNr, Name, Ort, Bezeichnung, Preis, Menge).
- 2NF – look for partial dependencies: BestellNr → Datum, KundenNr, Name, Ort. ArtikelNr → Bezeichnung, Preis. Only Menge needs both parts. Result: BESTELLUNG (BestellNr, Datum, KundenNr, Name, Ort), ARTIKEL (ArtikelNr, Bezeichnung, Preis), POSITION (↑BestellNr, ↑ArtikelNr, Menge).
- 3NF – look for transitive dependencies: in BESTELLUNG, BestellNr → KundenNr → Name, Ort. Name and Ort are moved out: KUNDE (KundenNr, Name, Ort), BESTELLUNG (BestellNr, Datum, ↑KundenNr). ARTIKEL and POSITION have no transitive dependencies.
- Result: four tables – KUNDE, BESTELLUNG, ARTIKEL, POSITION. Foreign keys: BESTELLUNG.KundenNr → KUNDE, POSITION.BestellNr → BESTELLUNG, POSITION.ArtikelNr → ARTIKEL.
- Check: if Ms Okafor moves, you change one single row in KUNDE. A new item can be entered in ARTIKEL without an order. If you delete order 502, customer 23 stays in KUNDE. All three anomalies are gone.
Foreign key on the n side, a junction table for m:n – and normalising means: atomic values (1NF), fully dependent on the whole key (2NF), dependent on nothing but the key (3NF).
Typical exam mistakes
- You put the foreign key of a 1:n relationship on the 1 side and then need a list in one cell.
- You check 2NF for a table with a single-attribute primary key and find partial dependencies that cannot exist there.
- You confuse partial dependency (2NF, part of the key) with transitive dependency (3NF, via a non-key attribute).
- You move attributes out but forget to leave the foreign key in the original table, so the link is lost.
Practice
Flashcards
Foreign key (Fremdschlüssel)
1:n and m:n in the relational model
The three anomalies
First normal form
Second normal form
Third normal form
Referential integrity
Exam-style task 15 marks
The invented music school Tonleiter Nord has so far managed enrolments in one table:
| SchuelerNr | Name | Telefon | Kurse |
|---|---|---|---|
| S04 | Brandt | 0111 2034 | K1 Gitarre (L3 Weber, 40 €, ab 01.09.); K4 Bandcoaching (L1 Yilmaz, 25 €, ab 15.09.) |
| S09 | Nowak | 0111 7781 | K1 Gitarre (L3 Weber, 40 €, ab 08.09.) |
Each course has a name, a monthly fee and exactly one teacher. The date states from when the student takes the course.
- Using this table, explain one example each of an insertion, an update and a deletion anomaly. (3 BE, Bewertungseinheiten = marks)
- Convert the table into first normal form and state the primary key. (3 BE)
- Convert the result step by step into second and third normal form. Name the dependency you remove in each step. Mark primary and foreign keys. (6 BE)
- Teacher L3 leaves the music school and is to be deleted. Explain what referential integrity requires here and evaluate two possible reactions of the database system. (3 BE)
Show solution
- Insertion: a new course without an enrolment cannot be stored, because it can only appear in a student's row. Update: if the fee for K1 rises, it has to be changed in the rows of Brandt and Nowak; if one is forgotten, the data contradict each other. Deletion: if Brandt leaves the school and her row is deleted, course K4 with its fee and teacher L1 Yilmaz disappear too, because only Brandt takes K4. (Any suitable example counts.)
- The course list is broken up, the values in brackets become separate columns: ANMELDUNG (SchuelerNr, KursNr, Name, Telefon, Bezeichnung, LehrerNr, LehrerName, Gebuehr, Beginn). Brandt has two rows, Nowak one. The key is composite because a SchuelerNr now appears more than once.
- 2NF: SchuelerNr → Name, Telefon and KursNr → Bezeichnung, LehrerNr, LehrerName, Gebuehr are partial dependencies; only Beginn depends on the whole key. Result: SCHUELER (SchuelerNr, Name, Telefon), KURS (KursNr, Bezeichnung, LehrerNr, LehrerName, Gebuehr), BELEGUNG (↑SchuelerNr, ↑KursNr, Beginn). 3NF: in KURS, KursNr → LehrerNr → LehrerName, a transitive dependency. Result: LEHRKRAFT (LehrerNr, Name), KURS (KursNr, Bezeichnung, Gebuehr, ↑LehrerNr). Final state: SCHUELER, KURS, LEHRKRAFT, BELEGUNG.
- No foreign key may point to a teacher who does not exist; but K1 still refers to L3. Refuse the deletion: safe, the school must first assign K1 to another teacher – sensible, because the course continues. Delete as well (cascade): K1 and all its enrolments would be deleted – unwanted here, because the students and the course continue. (Alternatively: set the foreign key to empty, only allowed if a course may temporarily have no teacher.)
Report a mistake
Reporting needs JavaScript. Or write to us via Contact.
Step 4 of 14
A topic counts as learned once you get 80% of the practice right first time.