AS Level · Topic 8.1
A-Level Computer Science 9618 / Topic 8 / AS

Store each fact once.

A school that keeps a separate file for the library, the exams office and the sports department soon has three different addresses for the same student. A relational database stores each fact once, in linked tables, and the database itself checks that the links stay valid.

The key idea

In a file-based approach each application keeps its own files, which leads to data redundancy (the same data stored many times), data inconsistency (copies that disagree) and data dependency (programs tied to the file structure). A relational database stores data about each entity in its own table (relation) of records (tuples) and fields (attributes). Each table has a primary key that uniquely identifies every record, and tables are linked by foreign keys. Referential integrity means every foreign key value must match an existing primary key value.

a foreign key links two tables MEMBER LOAN MemberIDFirstName LoanIDBookIDMemberID M01Aisha M02Ben M03Chloe M04Dev L01B101M01 L02B103M02 L03B102M01 L04B105M03 primary key foreign key each value must match a primary key
Fig. 1: MemberID is the primary key of MEMBER and a foreign key in LOAN
Section 01

The trouble with files.

Before databases, each department wrote its own program with its own data files. The library file and the exams file both held every student's name, form group and address. That approach has well-known limitations, and exam questions ask you to describe them precisely.

File-based limitationWhat it meansHow a relational database addresses it
Data redundancyThe same data is stored in several files, wasting storage.Each fact is stored once, in one table, and linked by keys.
Data inconsistencyA change is made in one file but not the others, so the copies disagree.With one copy, an update is made once and every user sees it.
Data dependencyPrograms are written for one file structure; changing the structure means rewriting the programs.The DBMS separates the data from the programs (program-data independence).
Poor integrityNothing checks that related data in different files still matches.Referential integrity and validation rules are enforced by the DBMS.
Weak security and sharingAccess is all-or-nothing for a whole file; sharing files between users is difficult.Access rights can be set per user or group; many users can share the data at once.
Hard to queryA new question needs a new program to be written.Ad hoc queries can be written in SQL.
Worked example Redundancy leads to inconsistency
A student moves house. The office updates her address in the admissions file, but the library file still holds the old one. Name and explain the two problems shown.
  1. The address is stored in two files: this is data redundancy.
  2. Only one copy was updated, so the two files now give different addresses: this is data inconsistency.
  3. In a relational database the address is stored once, in the STUDENT table, so there is only one copy to update.
Answer: Data redundancy causes data inconsistency
Examiner trap

Redundancy and inconsistency are not the same thing. Redundancy is the duplication; inconsistency is the result when duplicated copies are not all updated. Name the right one for the marks.

Section 02

Tables, tuples and attributes.

In the lab, the STUDENT, CLUB and MEMBERSHIP tables are shown with their primary keys underlined. Look at how each table holds data about one kind of thing, and how the keys repeat between tables.

TermMeaningLibrary example
EntityA person, object, event or idea about which data is storeda member, a book, a loan
Table (relation)Holds the data about one entity type, in rows and columnsMEMBER
Record (tuple)One row: the data about one instance of the entityM02, Ben, Okafor, 12B
Field (attribute)One column: one item of data about every instanceSurname
Primary keyAn attribute (or combination) that uniquely identifies each tupleMemberID
Candidate keyAny attribute (or minimal combination) that could be the primary key, because it is unique for every tupleMemberID, or a school email address
Secondary keyA candidate key not chosen as the primary key; it is often indexed so that searches on it are fastEmail
Foreign keyAn attribute in one table that is the primary key of another table, creating the linkMemberID in LOAN
Worked example Choosing keys
A table STUDENT(StudentID, Email, Surname, DateOfBirth) holds one record per student. Every student has their own school email address. Identify the candidate keys and suggest the primary key.
  1. Surname and DateOfBirth can repeat (two students can share them), so they cannot identify a tuple.
  2. StudentID is unique for every student; so is Email. Both are candidate keys.
  3. StudentID is short and never changes, so it is the better primary key. Email is then a secondary key.
Answer: Candidate keys StudentID and Email; primary key StudentID
Your turn
In the table LOAN(LoanID, BookID, MemberID, LoanDate, Returned), identify the primary key and the two foreign keys.
Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

What is meant by data redundancy?

Quick check+10 XP

Which term means the same as a tuple?

Quick check+10 XP

In the lab, why does DELETE FROM Club WHERE ClubID = 'C2' fail?

Quick check+10 XP

What is a candidate key?

Section 03

Keys that link.

Pick the lab example DELETE FROM Club WHERE ClubID = 'C2' and run it. The DBMS refuses, because memberships still point at club C2. Then try inserting a membership for a student who does not exist.

Worked example Will the DBMS allow it?
Using the MEMBER and LOAN tables in Fig. 1 (members M01 to M04), decide whether each change keeps referential integrity: (a) add loan L07 for book B102 and member M03; (b) add loan L08 for member M06; (c) delete member M02.
  1. (a) M03 exists in MEMBER, so the new foreign key value matches a primary key: allowed.
  2. (b) There is no M06 in MEMBER, so the loan would point at nothing: rejected.
  3. (c) Loan L02 still has MemberID M02, so deleting M02 would leave an orphan record: rejected (unless the loan is deleted first).
Answer: (a) allowed; (b) and (c) rejected
Examiner trap

Referential integrity is about foreign keys matching primary keys. It is not the same as validation (checking a value is sensible) or the uniqueness of a primary key.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

Which feature of a relational database removes the problem of data dependency?

Exam style+20 XP

LOAN(LoanID, BookID, MemberID, LoanDate). Which attribute is a foreign key?

Exam style+20 XP

Which of these would break referential integrity?

Exam style+20 XP

Why is the primary key field indexed?

Skill unlocked

Relational databases and keys, mastered.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Limitations of file-based storage, the features of a relational database, and every key term: entity, tuple, attribute, primary, candidate, secondary and foreign keys, referential integrity and indexing.