CS35: Relational Databases
Database concepts including tables, records, fields, primary keys, foreign keys, and how relational databases eliminate data inconsistency and redundancy.
Database concepts including tables, records, fields, primary keys, foreign keys, and how relational databases eliminate data inconsistency and redundancy.
Databases are used everywhere: schools store student records, shops store product and customer data, banks store account information. A well-designed database makes it easy to find, add, update, and delete data efficiently and accurately.
| StudentID | FirstName | LastName | Form | DateOfBirth |
|---|---|---|---|---|
| 1001 | Alice | Smith | 10A | 2008-03-15 |
| 1002 | Bob | Jones | 10B | 2008-07-22 |
| 1003 | Clara | Patel | 10A | 2008-11-09 |
Fields: StudentID, FirstName, LastName, Form, DateOfBirth
Records: 3 (one per student)
Each cell contains one piece of data (one field value for one record)
In a school, two students could have the same name "John Smith." A name field would not be unique, so it cannot be a primary key. A StudentID like "1001" is unique - no two students share the same ID.
Sometimes a single field isn't enough to uniquely identify a record. A composite primary key uses two or more fields together to create uniqueness. Example: In an "Enrolments" table, neither StudentID nor CourseID alone is unique (a student takes many courses, a course has many students). But the combination of StudentID + CourseID is unique for each enrolment.
Students Table:
| StudentID (PK) | FirstName | LastName | TutorGroupID (FK) |
|---|---|---|---|
| 1001 | Alice | Smith | TG01 |
| 1002 | Bob | Jones | TG02 |
TutorGroups Table:
| TutorGroupID (PK) | TutorName | Room |
|---|---|---|
| TG01 | Mr Williams | R12 |
| TG02 | Mrs Khan | R15 |
The TutorGroupID field in the Students table is a foreign key that references the primary key in the TutorGroups table. This links each student to their tutor group.
| Relationship Type | Notation | Description | Example |
|---|---|---|---|
| One-to-One | 1 : 1 | One record in table A relates to exactly one record in table B | Person : Passport (one person has one passport) |
| One-to-Many | 1 : M | One record in table A relates to many records in table B | Customer : Orders (one customer can have many orders) |
| Many-to-Many | M : N | Many records in table A relate to many records in table B | Students : Courses (many students take many courses) |
Students and Courses have a M:N relationship (many students take many courses; many courses have many students). We resolve this by creating an "Enrolments" linking table:
Students 1 : M Enrolments M : 1 Courses
The Enrolments table contains StudentID (FK) and CourseID (FK), forming a composite primary key.
| OrderID | CustomerName | CustomerAddress | Item | Price |
|---|---|---|---|---|
| 1 | Alice Smith | 12 Oak Lane | Widget A | 5.00 |
| 2 | Alice Smith | 12 Oak Lane | Widget B | 7.50 |
| 3 | Alice Smith | 45 Elm Road | Widget C | 3.00 |
Alice's address is stored three times (redundancy). In Order 3, her address is different from Orders 1 and 2 (inconsistency). Which is correct? We don't know.
By splitting data into separate related tables, each piece of data is stored only ONCE:
Customers Table: CustomerID, CustomerName, CustomerAddress (stored ONCE)
Orders Table: OrderID, CustomerID (FK), Item, Price
Alice's address is stored in only one place. If she moves, we update it once in the Customers table. No redundancy, no inconsistency.
| Mistake | Why It's Wrong | How to Fix It |
|---|---|---|
| Using a name as a primary key | Names are not necessarily unique | Use a unique ID number as primary key |
| Confusing primary key and foreign key | They serve different purposes | PK = uniquely identifies records; FK = links to another table's PK |
| Saying foreign keys must be unique | Foreign keys CAN repeat in a table | Only primary keys must be unique; foreign keys can repeat |
| Trying to create M:N relationship directly | Relational databases don't support M:N directly | Use a linking/junction table to resolve M:N |
| Confusing fields and records | Fields = columns; Records = rows | Field = category of data; Record = one complete set of data |
Q1: Define the terms field, record, and table in the context of a database.
Q2: What is a primary key? Why is it important?
Q3: Explain the difference between a primary key and a foreign key.
Q4: What is data redundancy and how does a relational database eliminate it?
Q5: How would you resolve a many-to-many relationship in a relational database?
On-screen programming exam plus theory paper. Eduqas's programming paper is completed on a computer with an IDE — practise typing working programs, not just reading them, under timed conditions.
Always check: specification details change — confirm paper structure and set texts against the current specification for your exam year.
✗ Thinking a flat file and a relational database are the same ✓ A flat file stores all data in a single table with redundant data. A relational database splits data into linked tables, reducing redundancy and improving data integrity.
✗ Confusing primary key and foreign key ✓ A primary key uniquely identifies each record in a table. A foreign key is a field in one table that references the primary key of another table, creating the relationship between them.
✗ Forgetting that a primary key must be unique and cannot be NULL ✓ Every record must have a unique primary key value — no duplicates and no empty (NULL) values. This ensures each record can be uniquely identified.
✗ Not understanding why normalisation reduces data redundancy ✓ Without normalisation, the same data (e.g. customer name) is repeated in multiple records. Normalisation splits this into separate tables linked by keys, so each piece of data is stored only once.
A school stores student data in a flat file with fields: StudentID, Name, TutorGroup, TutorName, TutorRoom. Explain two problems with this flat file design, and describe how a relational database would solve them. [5 marks]
Problem 1: Data redundancy — the TutorName and TutorRoom are repeated for every student in the same tutor group. If 30 students share a tutor, the tutor's name and room appear 30 times. Problem 2: Update anomaly — if a tutor changes room, every record for their students must be updated. Missing one record causes data inconsistency. Relational database solution: Students table: StudentID (PK), Name, TutorGroup (FK) Tutors table: TutorGroup (PK), TutorName, TutorRoom The TutorGroup field in Students is a foreign key linking to the Tutors table. Now each tutor's name and room are stored only once. If a tutor changes room, only ONE record in the Tutors table needs updating, eliminating redundancy and update anomalies.
AO1 (Computational Thinking — 40%): Demonstrate knowledge and understanding of the principles and concepts of computer science, including relational databases: primary keys, foreign keys and normalisation for AQA 8525, OCR J277 & Edexcel 1CP2.
AO2 (Application — 40%): Apply knowledge and understanding of computer science, including relational databases: primary keys, foreign keys and normalisation to analyse problems in computational terms and to design, write and evaluate solutions.
AO3 (Evaluation — 20%): Evaluate the effectiveness, correctness and efficiency of computational solutions, including relational databases: primary keys, foreign keys and normalisation, and make reasoned judgements about trade-offs.
Get the best revision books and guides to boost your grades.