A-Level Computer Science / Unit 8: Relational Databases and SQL

8.1.4 E–R Diagrams and Table Design

🔒 Lesson slides are available to signed-in users. Sign in

8.1.4 E–R Diagrams and Table Design

An entity–relationship (E–R) diagram represents entity types and how they relate. Cardinality and optionality should come from the scenario wording.

By the end of this page, you should be able to:

  • define and use the key terms accurately;
  • explain how the idea works using a new example;
  • apply the idea to a database design or SQL task.

1. Turn a description into entities

Read the scenario and identify the kinds of things that need their own records. A dance studio may need Learner, Class and Instructor entities. Avoid making an entity for every noun; it needs to represent data the system must retain.

2. Add attributes and identifiers

List the properties needed for each entity. Choose an attribute, or a combination, that uniquely identifies a record and mark it as the primary key. For example, Learner(LearnerID, Name, Email) may use LearnerID as its key.

3. Read minimum and maximum participation

Cardinality describes how many records can be related. Optionality describes the minimum. If a learner may attend zero or many classes, the relationship from Learner to attendance records is optional and one-to-many. Do not assume a minimum that the scenario does not state.

4. Translate the diagram into tables

In a one-to-many relationship, the primary key from the “one” entity is stored as a foreign key in the “many” entity. A many-to-many relationship needs a linking entity. For Learner and Class, Attendance(LearnerID, ClassID, AttendanceDate) can hold individual visits.

Worked example

A repair shop stores RepairJob and Technician. Each job has one assigned technician; a technician may have several jobs. Put TechnicianID as a foreign key in RepairJob. If a job can exist before assignment, the foreign key may be optional.

Common mistake to avoid

Do not put a one-to-many foreign key in the one-side table if it would need to store a list of many linked IDs in one field.

Interactive check

Choose an answer, read the explanation, and continue to the next example.

Try it

Check your understanding

Question 1 of 3
Score: 0 / 3

Independent practice

Try this original question before opening the suggested response.

A garden centre records Suppliers and Deliveries. A supplier may make many deliveries; each delivery comes from one supplier. State the entities, keys and foreign-key location. (4)

Suggested response

Supplier(SupplierID PK, SupplierName); Delivery(DeliveryID PK, DeliveryDate, SupplierID FK). Supplier to Delivery is one-to-many. SupplierID is stored in Delivery because Delivery is on the many side.

Answering clearly

Use the technical term, state what it does, and connect your explanation to the details in the question.