GGCSE Revision Hub

3.7.1 Relational databases

AQA Computer Science 8525Topic 3.7 — Relational databases and structured query languageFoundation & Higher

A database is an organised collection of data, and a relational database stores it in tables linked to each other. SQL is the language you use to ask a database questions. This topic is unusually practical: the SQL you need is a small, fixed set of commands, and the marks come from writing queries that are correct rather than from understanding theory. Learn the commands by their shape, then practise joining two tables together, because that is what the exam asks for.

What you need to know

What a database is

Explain the concept of a database. A database is a structured collection of data that can be stored, searched and updated efficiently. The point of the structure is that the data can be found again: a spreadsheet of 500 students is data, but a database with a defined table for students and a defined table for exam results is a database, because the arrangement of the data is part of the design.

Key fact: A database is a structured collection of data designed to be stored, searched and updated efficiently.

What makes it relational

Explain the concept of a relational database. A relational database stores the data in tables, and the tables are related to one another through keys. So the details of a student are stored once in a Students table, and the table of results refers to the student by an identifier rather than repeating the name and address on every row. The relationships are what make it relational.

Key fact: A relational database stores data in tables that are linked to each other through keys.

The vocabulary

Understand the following database concepts: table, record, field, data type, primary key and foreign key. A table is a grid of information about one kind of thing. A record is one row — one student. A field is one column — the student's name. A data type says what kind of value a field holds: text, number, date. A primary key uniquely identifies each record in its table. A foreign key is a field that refers to the primary key of another table.

Key fact: Table, record, field, data type, primary key, foreign key.

Primary keys

The primary key is the field that uniquely identifies each record in a table. It has to be unique and it cannot be empty, and it is what other tables use to refer to this record. Choosing a sensible primary key is a design decision: a name is a bad choice because two people can share it, and a field that can change is a bad choice because the links in other tables would break.

Key fact: A primary key uniquely identifies each record; it must be unique, not empty, and unlikely to change.

Foreign keys

A foreign key is a field in one table that refers to the primary key of another table. If the Results table has a column studentID that matches the primary key of the Students table, the two tables are related and you can join them. That link is what makes a relational database relational and what makes it possible to answer questions that span two tables.

Key fact: A foreign key refers to the primary key of another table and is what links the tables together.

Redundancy and inconsistency

Understand that the use of a relational database facilitates the elimination of data inconsistency and data redundancy. Data redundancy is storing the same fact in several places; data inconsistency is when one of those copies is wrong. If a student moves house and you update their address in one table but not in the other, the two records disagree and you no longer know which is right. Linking the tables removes the second copy, and with it the problem.

Key fact: Linking tables removes duplicated data and stops the copies disagreeing.

The alternative names

Note that whilst the terms entity, attribute and entity identifier are more commonly used when an abstract model of a database is being considered, the terms given here will be used for both implementations of and abstract models of databases. So in an exam answer, say table, record, field, data type, primary key and foreign key. If you say 'entity' the marker may still understand you, but the specification has been clear about which words it wants.

Key fact: Use table, record, field, data type, primary key and foreign key in exam answers, not entity, attribute or entity identifier.

Flashcards

Exam questions

Written in the style of AQA Computer Science, with a mark scheme for each one. No question here is a real past paper question.

mcq1 mark

A Results table contains a column studentID that matches the primary key of the Students table. What is studentID?

  • A field
  • A record
  • A data type
  • A foreign key

Mark scheme: 1 mark for identifying it as a foreign key, because it refers to the primary key of another table and so links the two tables together.

short3 marks

Explain in English what a primary key is, and give two requirements it must meet.

Mark scheme: 1 mark for stating that a primary key is the field that uniquely identifies each record in a table. 1 mark for stating that every value must be unique. 1 mark for stating that it cannot be empty, and ideally that it should not change once assigned.

six6 marks

Explain in English the structure of a relational database and how linking tables removes the problems of storing data separately.

Mark scheme: Level 1 (1-2 marks): A short answer saying a relational database is a set of linked tables. Level 2 (3-4 marks): A structured answer covering tables, records, fields, data types and the two kinds of key. Level 3 (5-6 marks): A detailed answer explaining the vocabulary, explaining that a primary key uniquely identifies a record and that a foreign key refers to it so the tables are linked, giving the example of students and results, and explaining that without the link the same address would be stored on every result row, which is data redundancy, and that updating only one copy would leave the database inconsistent, so the design removes both problems.

Other sections in this topic

Practise these questions

Answer them in the interactive view and they get marked against the same mark scheme, one mark at a time, with the reason for each mark.

Open the interactive topic →