AQA 7517, section 4.10.1
Before building a database, you need to decide what data to store and how the pieces of data relate to each other. A conceptual data model is a plan of this, drawn up from the data requirements of a scenario, independent of any particular database software.
The building blocks
| Term | Meaning | Example |
|---|---|---|
| Entity | A thing about which data is stored. It becomes a table | Student, Book, Order |
| Attribute | A property of an entity. It becomes a field (column) | A student's name, date of birth |
| Entity identifier | The attribute (or attributes) that uniquely identifies each instance of the entity | StudentID |
| Relationship | A link between two entities | A student borrows books |
An instance of an entity is one particular example, such as one particular student.
Types of relationship
Relationships are described by how many instances on each side can be linked.
| Type | Meaning | Example |
|---|---|---|
| One-to-one (1:1) | One instance of A is linked to at most one of B, and the other way round | A person and their passport |
| One-to-many (1:M) | One instance of A is linked to many of B, but each B has one A | One tutor group has many students |
| Many-to-many (M:M) | Many of A are linked to many of B | Students and books (a student borrows many books, and a book is borrowed by many students) |
The one-to-many relationship is the most common.
Entity relationship diagrams
An entity relationship (ER) diagram shows the entities and their relationships. Each entity is drawn as a box, and each relationship as a line joining the boxes. The "many" end of a relationship is shown with a crow's foot; the "one" end is a plain line.
A customer places many orders, and each order belongs to one customer. The crow's foot at the ORDER end shows this.
Many-to-many relationships
A many-to-many relationship can't be stored directly in a relational database. It is resolved by adding a link entity between the two, which gives two one-to-many relationships.
The Loan entity records each time that a student borrows a book, so it can hold extra data, such as the date borrowed.
Entity descriptions
Each entity is described by its name and attributes in the form
The attribute (or attributes) that form the entity identifier are underlined.
STUDENT (StudentID, Name, DateOfBirth, FormID)
In the descriptions below, the underlined attribute is the identifier. A foreign key (an attribute that is the identifier of another entity) is often marked with an asterisk or noted separately.
Drawing relationships from entity descriptions
Exam questions often give you the entity descriptions and ask you to complete the ER diagram. The foreign keys tell you the relationships:
- If entity B contains the identifier of entity A (as a foreign key), then A to B is one-to-many, with the crow's foot at B.
- If neither entity holds the other's identifier, and no link entity joins them, don't draw a line between them.
Example. A hospital stores:
WARD (WardID, WardName)
PATIENT (PatientID, Name, WardID)
CONSULTANT (ConsultantID, Name, Specialism)
APPOINTMENT (PatientID, ConsultantID, ApptDate, Room)
WardIDis in PATIENT, so WARD to PATIENT is one-to-many (a ward has many patients).PatientIDis in APPOINTMENT, so PATIENT to APPOINTMENT is one-to-many.ConsultantIDis in APPOINTMENT, so CONSULTANT to APPOINTMENT is one-to-many.- WARD and CONSULTANT share no key, so there is no line between them.
APPOINTMENT is a link entity: it resolves the many-to-many relationship between patients and consultants.
Producing a data model from requirements
- Read the requirements and underline the nouns. These are the candidate entities (and attributes).
- Decide what is an entity (needs its own details stored) and what is just an attribute of one.
- List the attributes for each entity and choose an identifier.
- Work out the relationships and their types (1:1, 1:M, M:M).
- Resolve any many-to-many relationships with a link entity.
- Draw the ER diagram and write the entity descriptions.
Worked example
Scenario: a school library lends books to students. For each student, it stores the name and tutor group. For each book, it stores the title, author and ISBN. When a book is borrowed, it records the date it was borrowed and the date it was returned. A student can borrow many books, and each book can be borrowed by many students (at different times).
Step 1: entities. Student, Book. (Loan is needed, as the date borrowed is a property of the borrowing, not of the student or the book.)
Step 2: relationships. A student borrows many books and a book is borrowed by many students, which is many-to-many, so it is resolved with the Loan link entity.
Step 3: the ER diagram.
Step 4: entity descriptions (identifiers underlined; the pair that identifies a loan is a composite identifier).
STUDENT (StudentID, Name, TutorGroup)
BOOK (ISBN, Title, Author)
LOAN (StudentID, ISBN, DateBorrowed, DateReturned)
A loan is identified by who borrowed which book when, since the same student could borrow the same book again on a later date. StudentID and ISBN in LOAN are also foreign keys, pointing back to STUDENT and BOOK.
Exam tip: in a data-modelling question, resolve every many-to-many relationship with a link entity, and underline the identifier in each entity description. Put the crow's foot on the many end. Don't draw relationships you're unsure of: AQA caps the marks if any incorrect relationship is drawn.
Check yourself
What is the difference between an entity and an attribute?
An entity is a thing about which data is stored (such as a student). An attribute is a property of an entity (such as the student's name).
How is a many-to-many relationship dealt with?
It is resolved by adding a link entity between the two, giving two one-to-many relationships.
A customer places many orders, and an order is for one customer. What type of relationship is this?
One-to-many (one customer to many orders).
Write an entity description for a Doctor with an ID, name and specialism
DOCTOR (DoctorID, Name, Specialism), with DoctorID underlined as the identifier.