Resolving many-to-many ERD
Students and clubs are many-to-many; a membership entity splits it and holds attributes of the relationship itself (joined date, role).
The diagram
Reading it step by step
- 'Student' has 2 attributes, primary key student_no.
- 'Club' has 2 attributes, primary key club_id.
- 'ClubMember' has 5 attributes, primary key membership_id, foreign key student_no, club_id.
- Each 'Student' relates to zero or more 'ClubMember'; each 'ClubMember' to exactly one 'Student' (joins).
- Each 'Club' relates to zero or more 'ClubMember'; each 'ClubMember' to exactly one 'Club' (admits).
Shape by shape
| Shape | Symbol | Connections |
|---|---|---|
| Student | Entity | holds student_no, name · → ClubMember(joins) |
| Club | Entity | holds club_id, club_name · → ClubMember(admits) |
| ClubMember | Entity | holds membership_id, student_no, club_id, joined_on, role · ← Student, Club |
Symbols used here
| Symbol | Meaning |
|---|---|
| Entity | A thing to store: name on top, attributes below. |
| Primary key (PK) | The attribute that identifies one row; underlined. |
| Foreign key (FK) | An attribute pointing to another entity's key. |
| Exactly one | Two short bars at the line end. |
| Zero or many | A crow's foot and a circle. |
Diagram text
Paste this text into the editor to get the same picture, then change the names to fit your own work.
# Resolving many-to-many ERD
erDiagram
Student {
int student_no PK
varchar name
}
Club {
int club_id PK
varchar club_name
}
ClubMember {
int membership_id PK
int student_no FK
int club_id FK
date joined_on
varchar role
}
Student ||--o{ ClubMember : joins
Club ||--o{ ClubMember : admits