ERD with relational schema
Entities, keys and relationships, then the tables.
What it explains and when it is useful
An entity relationship diagram (ERD) shows the things a database stores, their attributes and keys, and how they relate (one-to-many, many-to-many). The relational schema lists the actual tables.
When to use it: Any solution that uses a relational database (SQLite, MySQL, PostgreSQL, SQL Server).
Worked example
Illustrative: PracticePal is a fictional project used throughout this guide.
Scroll sideways to see the whole diagram.
Relational schema
STUDENT(student_id, name, email, password_hash, role)
ROOM(room_code, name, loud_allowed)
NEIGHBOUR(room_a*, room_b*) -- one row per shared wall
BOOKING(booking_id, student_id*, room_code*, start_time, end_time, loud, status)
UNIQUE(room_code, start_time)
WAITLIST_ENTRY(entry_id, student_id*, room_code*, slot_start, joined_at, state, offered_at)
ROOM_BLOCK(block_id, room_code*, from_date, to_date, reason)
underlined = primary key * = foreign keyThe many-to-many “room is next to room” relationship becomes the link table NEIGHBOUR. Field types, sizes and validation are in the data dictionary.
Notation and legend
| Symbol or part | Meaning |
|---|---|
| Box | Entity (becomes a table) |
| PK / FK | Primary key / foreign key |
| || | Exactly one |
| o| | Zero or one |
| |< (crow's foot + bar) | One or many |
| o< (crow's foot + circle) | Zero or many |
Design decisions it communicates
A diagram earns marks when you explain the decisions it shows. In PracticePal's documentation these would each be one sentence:
- A UNIQUE constraint on (room_code, start_time) backs up the clash check (SC4).
- NEIGHBOUR is a link table, so rooms can be re-arranged without changing code (SC6).
- Waiting-list entries are rows, not a list in memory, so the queue survives a restart (SC7).
- The schema is in 3NF: no repeated student or room details in BOOKING.
Common mistakes
- Leaving many-to-many relationships without a link table.
- No keys shown.
- Methods inside entities (that is a class diagram).
- Cardinality symbols at the wrong ends.
Checklist for your own version
Ticks are saved in this browser only, so you can use the list while you draft.