What you'll learn
Databases store the huge amounts of structured data that modern systems rely on, and relational databases organise that data into linked tables. For AQA GCSE Computer Science you need to understand what a relational database is, the key terms, why data is organised into linked tables, and how to use SQL to retrieve and change data. This guide covers databases and their structure, keys and relationships, and the main SQL commands. By the end you should be able to describe a relational database and write basic SQL queries.
Key terms and definitions
Database — An organised, persistent store of data.
Relational database — A database that organises data into linked tables.
Table — A structure holding data about one type of thing, arranged in records and fields.
Record (row) — All the data about one item in a table.
Field (column) — One item of data stored for every record.
Primary key — A field that uniquely identifies each record in a table.
Foreign key — A field in one table that refers to the primary key of another, linking the tables.
SQL — Structured Query Language, used to manage and query databases.
Core concepts
What a database is
A database is an organised store of data that can be searched, sorted and updated. A simple database might be a single table (a "flat file"), but this leads to problems: data is often repeated in many records, which wastes space and can cause errors and inconsistencies if the same information is stored in more than one place. Relational databases solve this by splitting the data across linked tables.
Relational databases and tables
A relational database organises data into two or more tables, each about one type of thing (for example, one table for students and another for courses). Each table is made of:
- Records (rows) — each record holds all the data about one item.
- Fields (columns) — each field holds one piece of data stored for every record.
By splitting data into separate tables and linking them, a relational database avoids repeating data, saves space, and keeps data consistent — if a piece of information changes, it only has to be changed in one place.
Primary keys
Every table needs a primary key — a field that uniquely identifies each record, so no two records have the same value. For example, a student table might use a unique student ID as the primary key. The primary key ensures each record can be found and referred to without confusion. A good primary key is unique and never changes.
Foreign keys and relationships
Tables are linked using foreign keys. A foreign key is a field in one table that refers to the primary key of another table. For example, an "enrolments" table might contain a student ID (a foreign key linking to the student table) and a course ID (a foreign key linking to the course table). This is how relational databases connect data across tables — the foreign key creates a relationship between them, so related data can be brought together without storing it repeatedly.
SQL: retrieving data
SQL (Structured Query Language) is used to manage and query databases. The most common command retrieves data:
- SELECT chooses which fields to return.
- FROM states which table to use.
- WHERE filters the records to those that meet a condition.
- ORDER BY sorts the results.
For example: SELECT name, age FROM students WHERE age > 15 ORDER BY name returns the name and age of students older than 15, sorted by name.
SQL: changing data
SQL can also change data in the database:
- INSERT INTO adds a new record to a table.
- UPDATE changes data in existing records (usually with a WHERE condition to choose which).
- DELETE removes records (again, usually with a WHERE condition).
For example: INSERT INTO students (name, age) VALUES ('Ana', 16) adds a new student record. Being able to read and write these basic SQL commands is a common exam requirement.
Choosing data types and validation
When a database table is designed, each field is given a data type that says what kind of data it holds — for example, integer (whole numbers), real (decimals), Boolean (true/false), text/string, or date/time. Choosing the correct data type matters because it saves storage, prevents invalid data, and allows the right operations (you can do arithmetic on numbers but not on text). Databases can also apply validation to check that data entered is sensible — for example, a range check that an age is between 0 and 120, or a format check that an email contains an "@". Using appropriate data types and validation keeps the data accurate and consistent, which is one of the main advantages of a well-designed database over a loosely organised store of information.
Advantages of SQL for querying data
SQL is powerful because it lets you retrieve exactly the data you want from large tables with a short, precise command, rather than searching by hand. A single SELECT statement can filter records with WHERE, sort them with ORDER BY, and even combine data from more than one table using their keys, so you can answer complex questions about the data quickly. For example, you could list every student enrolled on a particular course by linking the students and enrolments tables through their keys. Because SQL is a standard language used by many database systems, learning it means you can query many different databases. Being able to explain why SQL is useful — precise, flexible retrieval from large, linked datasets — shows an understanding of why relational databases and SQL are so widely used.
Worked examples
Example 1: Why use a relational database
Explain one advantage of a relational database over a single flat-file table. A relational database splits data into linked tables, which avoids repeating the same data in many records. This saves storage space and keeps data consistent, because information only needs to be stored and updated in one place, reducing errors.
Example 2: Primary and foreign keys
Explain the difference between a primary key and a foreign key. A primary key uniquely identifies each record in its own table. A foreign key is a field in one table that refers to the primary key of another table, creating a link (relationship) between the two tables.
Example 3: Writing a SELECT query
Write an SQL query to return the names of all students in the "students" table whose grade is 'A'. SELECT name FROM students WHERE grade = 'A'. SELECT chooses the name field, FROM names the table, and WHERE filters to records where the grade is 'A'.
Example 4: Updating a record
Write an SQL command to change the age of the student named 'Ana' to 17. UPDATE students SET age = 17 WHERE name = 'Ana'. UPDATE names the table, SET gives the new value, and WHERE selects which record(s) to change, so only Ana's record is updated.
Common mistakes and how to avoid them
A common error is confusing records and fields. A record (row) is all the data about one item; a field (column) is one piece of data stored for every record. Keep them straight.
Students often muddle primary and foreign keys. A primary key uniquely identifies records in its own table; a foreign key links to the primary key of another table. Learn the difference.
Another mistake in SQL is forgetting the WHERE clause in UPDATE or DELETE. Without WHERE, the command affects every record in the table, which can wipe or change all the data. Always include a condition unless you really mean all records.
When writing SELECT queries, remember the order: SELECT fields, FROM table, WHERE condition, ORDER BY to sort. Getting the clauses in the wrong order is a common slip.
Finally, remember the whole point of a relational database is to avoid repeating data. If your design stores the same information in many places, it is not making good use of the relational model.
Exam technique for "Relational Databases and SQL"
Be ready to define the key terms (table, record, field, primary key, foreign key) and to explain why relational databases split data into linked tables — to avoid repetition, save space and keep data consistent.
Practise reading and writing SQL commands: SELECT ... FROM ... WHERE ... ORDER BY for queries, and INSERT, UPDATE and DELETE for changing data. Pay attention to the WHERE clause, and use quotation marks around text values.
Be able to identify primary and foreign keys in a given database and explain the relationship they create. Use precise terms — relational database, primary key, foreign key, SQL, SELECT — throughout, and write SQL with the clauses in the correct order.
Quick revision summary
- A relational database organises data into linked tables to avoid repeating data, saving space and keeping data consistent.
- A table has records (rows) and fields (columns).
- A primary key uniquely identifies each record; a foreign key links to another table's primary key, creating a relationship.
- SQL queries data with SELECT fields FROM table WHERE condition ORDER BY sort.
- SQL changes data with INSERT INTO, UPDATE ... SET ... WHERE, and DELETE ... WHERE.
- Always include a WHERE clause in UPDATE/DELETE, or every record is affected.