Normalisation · נורמליזציה
Why normalise?
Imagine storing every club booking in one table, with the coach repeated on every row: each booking of the Chess club would carry "Mr Ng" again and again.
That repetition causes problems. If Mr Ng leaves, you must update many rows; miss one and the data becomes inconsistent. Normalisation organises tables to remove this kind of redundancy.
מדוע נורמליזציה?
דמיינו אחסון כל הזמנה במועדון בטבלה אחת, כאשר המדריך מופיע בשורה בכל פעם: כל הזמנה למועדון השחמט תכיל שוב ושוב את "גבר נג".
השחזור הזה גורם לבעיות. אם גבר נג עוזב, עליכם לעדכן רבות שורות; אם תפספסו אחת, הנתונים ייהפכו לאינצ'יסטיים. נירול מארגן טבלות כדי להסיר סוג זה של כפילות.
The normal forms
You normalise in steps:
- 1NF — every cell holds a single value (no lists or repeating groups), and the table has a primary key.
- 2NF — already 1NF, and no non-key column depends on only part of a composite key.
- 3NF — already 2NF, and no non-key column depends on another non-key column (no transitive dependency).
In the one-table version, coach depends on the club, not on the booking — a transitive dependency, so it is not in 3NF.
צורות הנירול
מתבצעים שלבים של נירול:
- 1NF — כל תא מכיל ערך יחיד (ללא רשימות או קבוצות חוזרות), והטבלה כוללת מפתח ראשוני.
- 2NF — כבר ב-1NF, ואין עמודה שאינה מפתח התלויה רק ב-חלק ממפתח מורכב.
- 3NF — כבר ב-2NF, ואין עמודה שאינה מפתח התלויה ב-עמודה שאינה מפתח אחר (ללא תלות מעברית).
בגרסה בעלת טבלה אחת, coach תלוי ב-club, ולא בהזמנה — זוהי תלות מעברית, ולכן היא אינה ב-3NF.
The normalised design
We split the data into two tables (the ones loaded here):
club(club_id, name, coach)— each club and its coach, stored once.booking(booking_id, student, club_id)— each booking, linked by the foreign keyclub_id.
Now a coach is stored once. A JOIN puts the information back together whenever you need it — write that join below.
העיצוב המנורל
חילקנו את הנתונים לשתי טבלות (אלו שנטענו כאן):
club(club_id, name, coach)— כל קבוצה ומאמנה, מאוחסנים פעם אחת.booking(booking_id, student, club_id)— כל הזמנה, מקושרת על ידי המקרא החיצוניclub_id.
כעת מדריך מאוחסן פעם אחת. חיבור (JOIN) משלב את המידע חזרה כל פעם שאתם זקוקים לו — כתבו חיבור כזה למטה.
Common mistakes
- Split repeating groups into their own table instead of many similar columns.
- Each table should describe one kind of thing.
טעויות נפוצות
- חלקו קבוצות חוזרות לטבלה עצמאית במקום ליצירת הרבה עמודות דומות.
- לכל טבלה צריך להיות תיאור של סוג אחד של דבר.
Reassemble the data: list each booking's student next to their club's coach, by joining booking to club on club_id, ordered by booking.booking_id. · אחד מחדש את הנתונים: רשימו עבור כל הזמנה את הstudent שלה לצד הcoach של המועדון, על ידי חיבור booking לclub לפי club_id, ומיון לפי booking.booking_id.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
The split tables still answer questions together. Count how many bookings each club has: join booking to club, show club.name and COUNT(*) AS bookings, group by the club, and order by club.name. · הטבלות המופרדות עדיין עונות יחד על שאלות. ספרו כמה הזמנות יש לכל מועדון: חברו booking לclub, הצגו club.name וCOUNT(*) AS bookings, קבצו לפי המועדון, ומיינו לפי club.name.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.