Understand database relationships (one-to-one, one-to-many)
10 Database and File Concepts
Objective: Understand database relationships (one‑to‑one, one‑to‑many)
In a database, relationships describe how data in one table is connected to data in another. Think of it like a social network: your friends (rows) are linked to you (another row). We’ll look at two common types: one‑to‑one and one‑to‑many.
One‑to‑One Relationship
A one‑to‑one relationship means that each row in Table A is linked to exactly one row in Table B, and vice versa. Imagine a passport and a person – each person has one passport, and each passport belongs to one person.
| Person (Table A) | Passport (Table B) |
|---|---|
| John Doe (PK: 1) | Passport #123456 (FK: 1) |
| Jane Smith (PK: 2) | Passport #654321 (FK: 2) |
In LaTeX notation, this can be expressed as:
$1 \times 1$ relationship
One‑to‑Many Relationship
A one‑to‑many relationship means that one row in Table A can be linked to multiple rows in Table B, but each row in Table B is linked to only one row in Table A. Think of a teacher and the students they teach.
| Teacher (Table A) | Student (Table B) |
|---|---|
| Ms. Lee (PK: 10) | Alice (FK: 10) |
| Bob (FK: 10) | |
| Mr. Kim (PK: 11) | Charlie (FK: 11) |
LaTeX notation:
$1 \times N$ relationship
Real‑World Analogy
- 📘 One‑to‑One: A student’s student ID card and the student record – each card belongs to one student, and each record has one card.
- 📚 One‑to‑Many: A library and its books – one library can hold many books, but each book is stored in only one library.
Exam Preparation Checklist
- Identify primary and foreign keys in each table.
- Determine the cardinality: 1:1 or 1:N.
- Draw a simple diagram or use a table to illustrate the relationship.
- Explain the real‑world meaning of the relationship.
- Practice converting a written description into a relational diagram.
Revision
Log in to practice.