Normalisation
ВведеноВ этом уроке
| English | Значение |
|---|---|
| insert anomaly/ˈɪnsɜːt əˈnɒməli/ | аномалия вставки |
| update anomaly/ˈʌpdeɪt əˈnɒməli/ | аномалия обновления |
| delete anomaly/dɪˈliːt əˈnɒməli/ | аномалия удаления |
| functional dependency/ˈfʌŋkʃənl dɪˈpendənsi/ | функциональная зависимость |
| Second normal form/ˈsekənd ˈnɔːml fɔːm/ | no non-key column depends on only part of a composite key |
| third normal form/θɜːd ˈnɔːml fɔːm/ | третья нормальная форма |
| Boyce-Codd normal form/bɔɪs kɒd ˈnɔːml fɔːm/ | every determinant in the table is a candidate key |
| denormalisation/dɪˌnɔːməlaɪˈzeɪʃn/ | deliberately adding redundancy to a schema to make reads faster |
| lossless/ˈlɒsləs/ | Describing compression from which the original data can be recovered exactly. |
| spurious rows/ˈspjʊərɪəs rəʊz/ | wrong extra rows created when a table is split and joined back badly |
| attribute closure/ˈætrɪbjuːt ˈkləʊʒə/ | the set of all attributes that a given set of attributes determines through the functional dependencies |
The anomalies
- A table that is not normalised causes three problems. An insert anomaly 插入异常: you cannot add a course that has no student yet.
- An update anomaly 更新异常: one fact must be changed in many rows. A delete anomaly 删除异常: deleting the last row that holds a fact loses the fact.
- The cause in every case is a fact that is stored more than once.

Changing a course title in 14 enrollment rows is —
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
One fact stored many times: the update anomaly.
Dependencies drive the split
- A functional dependency 函数依赖 $A \to B$ means each value of A fixes one value of B. Second normal form 第二范式 removes dependencies on part of the key; third normal form 第三范式 removes transitive ones (through another column); Boyce-Codd normal form BC范式 makes every determinant a key.
- In
Enroll(student, course, title, dept, building),course → titledepends on part of the key, andtitle → dept → buildingis transitive. Split it into Course, Dept and Enroll: each fact is stored once, and every anomaly is gone.
A part-key dependency breaks —
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
2NF removes dependencies on part of the key; 3NF the transitive ones.
Put the steps of normalising a table in order.
Сложность 3/5 · 200 монет + небольшой бонус за первое завершение сегодня
Each form assumes the one before it: you cannot see a transitive dependency on a key until the part-key ones are split out.
When to stop
Room(building, room, capacity, projector_type), where all rooms in a building have the same projector type:building → projector_typehas a determinant that is not a key. Split offBuilding(building, projector_type).- A stored running total can be computed from other data, but computing it again for every view may cost more than the risk of an anomaly.
- Controlled denormalisation 反规范化 with a refresh trigger is fine once you understand the normal form. Normalise to reason; denormalise when measurements show the need.
A non-key column determining another breaks —
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
A transitive chain through a non-key determinant is the 3NF violation.
Lossless splits
- A split must be lossless 无损: joining the parts gives back exactly the original rows. The test: the shared columns must be a key of one of the parts.
Enroll(student, course)andCourse(course, title, dept)sharecourse, the key of Course, so the join is exact. - Split on
titleinstead, into(student, title)and(course, title), and two courses with the same title join into spurious rows 伪元组 that were never there. 3NF can always be reached losslessly while keeping every dependency; BCNF is always lossless but can lose a dependency.
R(A, B, C) with A → B is split into R1(A, B) и R2(A, C). The split is —
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
The shared column A determines B, so it is a key of R1 and the join returns exactly the original rows.
A BCNF decomposition always preserves every functional dependency.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
BCNF is always lossless but can lose a dependency; 3NF can always keep both.
Find the keys with closure
- The attribute closure 属性闭包 $X^+$ is everything that $X$ determines. For $R(A, B, C, D)$ with $A \to B$, $B \to C$, $C \to D$: $A^+ = \{A, B, C, D\}$, so $A$ alone is a key.
- $B^+ = \{B, C, D\}$ does not contain $A$, so $B$ is not a key. Closure turns "is this a key?" and "does this dependency follow?" into a mechanical check.
$R(A, B, C, D)$ with $A \to B$, $B \to C$, $C \to D$. $B^+$ is:
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
$B \to C \to D$, but nothing gives $A$.
In that relation, $A$ is a key.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
$A^+$ contains every attribute.
Worked example: 3NF but not BCNF
Teach(student, course, instructor): each instructor teaches one course (instructor → course), and a student has one instructor per course (student, course → instructor).instructoris a determinant but not a key, so the table is not in BCNF. Splitting into(instructor, course)and(student, instructor)is lossless, but no single table now enforcesstudent, course → instructor. In this case 3NF is the better place to stop.
Teach(student, course, instructor) with instructor → course is in BCNF.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
Instructor determines course but is not a key.
Marks that slip away
- Splitting on a non-key. Split on
titleand two courses that share a title join into spurious rows. - Mixing up the two dependencies.
course → titlein the enrolment table depends on part of the key (a 2NF problem);title → dept → buildingis transitive (a 3NF problem). - Normalising past the evidence. Controlled denormalisation with a refresh rule is fine once measured reads need it.
Recap
- Anomalies come from repeated facts: insert, update and delete. Each normal form removes one cause:
| Form | Removes, with this lesson's case |
|---|---|
| 2NF | dependence on part of the key: course → title |
| 3NF | transitive dependence: title → dept → building |
| BCNF | a determinant that is not a key: instructor → course |
- Normalise to reason; denormalise when measurements show the need.
Что пошло не так? Это увидит только команда сайта.