ERDs
What Is an Entity Relationship Diagram (ERD)?
An Entity Relationship Diagram (ERD) is a visual model that shows data entities and the relationships between them within a database system.
ERDs are essential tools for designing logical and efficient database structures before implementation.
Key Components of an ERD
Entities
Entities represent real-world objects that are stored as records in a table. Each entity becomes a table in a relational database.
Examples: Student, Course
Attributes
Attributes are the properties or details of an entity, stored as fields within the table.
Examples: StudentID, CourseName
Relationships
Relationships define how two entities are associated with each other.
Example: Student enrols in Course, Teacher assigned to Course
Cardinality
Cardinality defines the number of instances of one entity that can be associated with instances of another entity.
- One-to-One (1:1): One (each) student has one ID card. Each (one) ID card has one student.
- One-to-Many (1:M): One (each) teacher teaches many classes - defining the Many side of relationship. Each (one) class has one teacher - defining the one side of relationship.
- Many-to-Many (M:N): Many students enrol in many courses. Or, one (each) student is enrolled in many courses - defining one half of the Many side of relationship. One (each) course has many students enrolled - defining the other half of the Many side of relationship.
Cardinality: One-to-One (1:1)
Each student has one ID card, and each ID card belongs to one student.
Students
| StudentID (PK) | Name |
|---|---|
| 1001 | Amira Khan |
| 1002 | Lucas Patel |
IDCards
| CardID (PK) | StudentID (FK) |
|---|---|
| ID1001 | 1001 |
| ID1002 | 1002 |
Explanation: Student 1001 (Amira) has one ID card (ID1001), and that ID card belongs only to her. The same applies to student 1002 and card ID1002 - this shows a true 1:1 relationship.
A 1:1 relationship
Cardinality: One-to-Many (1:M)
Each teacher can teach many classes, but each class has only one teacher.
Teachers
| TeacherID (PK) | Name |
|---|---|
| T01 | Ms Roberts |
| T02 | Mr Clark |
Classes
| ClassID (PK) | Subject | TeacherID (FK) |
|---|---|---|
| C101 | Maths | T01 |
| C102 | English | T01 |
| C103 | History | T02 |
Explanation: Teacher T01 (Ms Roberts) teaches two classes: Maths and English. Teacher T02 (Mr Clark) teaches History. Each class has exactly one teacher, but a teacher may teach multiple classes - this is a 1:M relationship.
A 1:M relationship
Cardinality: Many-to-Many (M:N)
Students can enrol in many courses, and each course may have many students. A linking (or junction) table (Enrolments) connects them.
NOTE: In a relationship such as this, you ALWAYS introduce a junction table.
Students
| StudentID (PK) | Name |
|---|---|
| 2001 | Isla Green |
| 2002 | Kian Ahmed |
Courses
| CourseID (PK) | Title |
|---|---|
| CS01 | Computer Science |
| PH01 | Physics |
Enrolments
| StudentID (FK) | CourseID (FK) |
|---|---|
| 2001 | CS01 |
| 2001 | PH01 |
| 2002 | PH01 |
Explanation: Student 2001 (Isla) is enrolled in two courses - CS01 and PH01. Student 2002 (Kian) is enrolled in PH01. The course PH01 is taken by both Isla and Kian. This shows a many-to-many relationship where both students and courses can appear multiple times in the Enrolments table.
A M:N relationship
Modality
Modality defines whether corresponding records in a relationship are optional or required.
- Mandatory: Every order must have a customer.
- Optional: A student may have a project, but not all students are assigned one.
Modality: Mandatory
In a mandatory relationship, each record in the dependent table must be linked to an existing record in the parent table. Orders must always be associated with a valid customer. However, a customer can exist without an (active) order.
Customers
| CustomerID (PK) | Name |
|---|---|
| C001 | Sarah Lee |
| C002 | James Grant |
Orders
| OrderID (PK) | CustomerID (FK) | Item |
|---|---|---|
| O1001 | C001 | Laptop |
| O1002 | C001 | Tablet |
| O1003 | C999 | Tablet |
| O1004 | Tablet |
✅ Valid: O1001 is linked to an existing customer.
✅ Valid: O1002 is linked to an existing (the same) customer.
❌ Invalid: O1003 references a customer (C999) that does not exist.
❌ Invalid: O1004 does not reference a customer at all.
A mandatory relationship: the 'cross' on the 1 side denotes mandatory. The 'circle' on the Many side denotes optional.
Modality: Optional
In an optional relationship, some records may not be linked to others. Participation in the relationship is not required.
Example 1: Optional 1:M – Not every student has a project
Students
| StudentID (PK) | Name | ProjectID (FK) |
|---|---|---|
| 3011 | Ella Tran | P001 |
| 3012 | Leo Nair | null |
🟡 Leo has no project - this is allowed in an optional relationship.
Projects
| ProjectID (PK) | Title |
|---|---|
| P001 | Climate Analysis |
| P002 | AI in Education |
Example 2: Optional M:N – Some students have not enrolled in any club
Students
| StudentID (PK) | Name |
|---|---|
| 5011 | Maya Wong |
| 5012 | Daniel Chen |
Clubs
| ClubID (PK) | Name |
|---|---|
| CL01 | Science Club |
| CL02 | Chess Club |
| CL03 | Art Club |
🟡 Art Club is not in the Memberships table - this is valid in optional M:N.
Memberships
| StudentID (FK) | ClubID (FK) |
|---|---|
| 5011 | CL01 |
| 5011 | CL02 |
🟡 Daniel is not in the Memberships table - this is valid in optional M:N.
Explanation: Optional relationships allow some records to remain unlinked. For example, Daniel (5012) is a valid student who hasn’t joined a club. Similarly, Leo (3012) doesn’t yet have a project. These are acceptable in systems that support optional modality.
An optional relationship: the 'circles' denote optional.
Common ERD Notations
| Symbol | Meaning | Example |
|---|---|---|
| Rectangle | Represents an entity | Student, Course |
| Oval | Represents an attribute | StudentName, CourseID |
| Diamond | Represents a relationship | Enrolled, Assigned |
| Lines | Show connections between entities and relationships | Connects Student to Course |
Why ERDs Matter
- Visual Planning: Simplifies database design before implementation.
- Efficient Modelling: Supports logical structuring of data and relationships.
- Improves Integrity: Encourages good database practices to avoid anomalies.
- Supports Scalability: Adapts well to new entities and relationships as the system grows.
Key Takeaways
- Entity Relationship Diagrams (ERDs) visually represent entities, attributes, and relationships in a database.
- They help with planning, structuring, and optimising relational databases.
- Cardinality shows how many entities relate; modality shows whether participation is required.
- ERDs are essential in ensuring data integrity, clarity, and future expansion.