24 min read
One-to-One
One member, one locker. The foreign key lives in Lockers and must not repeat.
One Member, One Locker
Emily Brooks arrives at Riverside Public Library with a bag she does not want to carry.
Oliver Bennett nods. “One member, one locker. Your locker is yours. You do not get a second one.”
Amelia Hart writes it down. Emily is MemberID 3. Her locker is Ground floor A3.
If Amelia wrote “A3” on Emily's membership card, the locker has no identity. Oliver Bennett cannot list empty lockers.
So she starts Lockers. Each row is one locker. Each locker stores the member it belongs to.
Read both ways:
- Emily has one locker.
- Ground floor A3 belongs to one member.
That is one-to-one: ONE member, ONE locker.
Click the table name, a column heading, or any value. Each piece has a job.
Where the Foreign Key Sits
The foreign key is Lockers.MemberID. It lives on Lockers, not on Members.
Because the relationship is one-to-one, MemberID must not repeat in Lockers. Emily's 3 appears once.
Members and lockers
The bar marks the ONE side (the primary key). The three lines mark the MANY side (the foreign key). The line joins those two fields — it is not a flow of data.
Click a key icon, a field name, or a relationship line to highlight the matching fields.
Look both ways
| Members → Lockers | Lockers → Members |
|---|---|
| Each member has at most one locker | Each locker belongs to at most one member |
| Emily (3) → Ground floor A3 only | Ground floor A3 → Emily only |
Loans are different. Sophie Walsh has two loans — that is one-to-many. Lockers are the exception at this library: one-to-one.
Do not call them the same shape because both use MemberID. The counts differ.
Putting LockerID on Members and MemberID on Lockers means two pointers for the same fact. They can disagree. Store the foreign key once. For lockers, it lives in Lockers.MemberID.
Practice
Swipe or use the arrows to move between questions.
1 / 3
More lessons in Database Fundamentals · Next: Data Integrity and Invalid Data · Previous: Many-to-Many
