Skip to topic
    ← Back to course topics

    Relational databases and structured query language (SQL) — AQA GCSE Computer Science

    Test yourself on Relational databases and structured query language (SQL) with AQA GCSE practice questions.

    Start free

    7 days Premium · Then free forever · No card, no charge

    Relational databases and structured query language (SQL) explained

    This topic introduces the fundamental concepts of relational databases, focusing on how data is structured and managed to ensure integrity.

    Read the full explanation

    Students learn about the core components of a database, including tables, records, fields, and the use of primary and foreign keys to establish relationships between data entities.

    What to demonstrate

    1. Definition of a database as a structured collection of data
    2. Explanation of a relational database as a collection of tables linked by keys
    3. Identification of key components: table, record, field, and data type
    Show all 6 objectives
    1. Correct use of primary keys to uniquely identify records
    2. Correct use of foreign keys to link tables
    3. Understanding that relational databases eliminate data inconsistency and redundancy

    Relational databases and structured query language (SQL) exam tips

    Topic Overview

    Relational databases and SQL are fundamental concepts in computer science, enabling efficient storage, retrieval, and manipulation of large datasets. At GCSE level, you will learn how data is organised into tables (also called relations) made up of rows (records) and columns (fields). Understanding the structure of relational databases and the importance of primary and foreign keys is essential for creating robust data systems. This topic underpins modern software applications, from e-commerce websites to social media platforms, where data must be accessed quickly and reliably.

    Structured Query Language (SQL) is the standard language used to interact with relational databases. The AQA GCSE specification focuses on writing basic SQL statements to query and modify data: SELECT for retrieval, INSERT INTO for adding records, UPDATE for changing existing data, and DELETE for removal. You will also learn to filter results using WHERE clauses, sort with ORDER BY, and combine conditions with AND, OR, and NOT. Mastering these commands allows you to answer real-world data questions and is a skill highly valued in many careers.

    Within the wider computer science curriculum, databases bridge the gap between theory and practical application. They build on earlier topics like data representation and lay the groundwork for more advanced areas such as web development and big data. For your exam, you must be able to define key terms, design simple databases by identifying keys and relationships, and write accurate SQL statements. This topic frequently appears in Paper 2 and requires both conceptual understanding and precise technical writing.

    Key Concepts
    • →Relational database structure: Data is organised into tables (relations) consisting of rows (records/tuples) and columns (fields/attributes). Each column has a defined data type (e.g., integer, text, date).
    • →Primary and foreign keys: A primary key is a unique identifier for each record in a table (cannot be null). A foreign key is a field in one table that references the primary key in another, establishing a relationship and maintaining referential integrity.
    • →Relationships between tables: One-to-one (e.g., a person and their passport), one-to-many (e.g., a customer and their orders – one customer places many orders), and many-to-many (e.g., students and courses – resolved using a linking table with two foreign keys).
    • →SQL data manipulation: Key commands include SELECT...FROM...WHERE (retrieve data), INSERT INTO...VALUES (add records), UPDATE...SET...WHERE (modify records), and DELETE FROM...WHERE (remove records). Wildcards like % and operators AND, OR, NOT are used for flexible filtering.
    • →Data integrity and normalisation: Normalisation reduces data redundancy by splitting data into related tables. While you don’t need to know normal forms in detail, you should understand why duplicated data is problematic (e.g., update anomalies) and how keys enforce integrity.
    Marking Points
    • Definition of a database as a structured collection of data
    • Explanation of a relational database as a collection of tables linked by keys
    • Identification of key components: table, record, field, and data type
    • Correct use of primary keys to uniquely identify records
    • Correct use of foreign keys to link tables
    • Understanding that relational databases eliminate data inconsistency and redundancy
    Examiner Tips
    • 💡Ensure you can distinguish between a primary key and a foreign key in a given scenario
    • 💡Be prepared to explain how relational databases reduce data redundancy compared to flat-file systems
    • 💡Practice identifying fields and records in provided database table examples
    • 💡When designing tables or identifying keys, always underline the primary key and clearly label foreign keys with (FK). In SQL questions, use UPPERCASE for keywords and single quotes for text values to improve clarity and avoid losing marks for syntax.
    • 💡Read the question carefully to determine exactly which fields to return. If the question asks for 'name and date of birth', selecting * (all fields) will lose marks. Similarly, check whether sorting is required and whether you need to filter by specific conditions.
    • 💡In extended response questions, show your working: even if your final SQL is slightly off, you can gain marks for a correct WHERE clause or understanding of key relationships. Always consider edge cases, like handling null values or empty result sets.
    Common Mistakes
    • Confusing the terms entity and attribute with table and field
    • Failing to identify the correct primary key for a given table
    • Misunderstanding the purpose of a foreign key in maintaining relationships
    • Assuming that all databases are relational
    • Confusing primary and foreign keys: Students often think a foreign key must be unique like a primary key. Correction: A foreign key can have duplicate values because it’s used to link multiple records to the same parent row. Only primary keys must be unique and not null.
    • Using = with wildcards in SQL: Many write WHERE name = 'A%', expecting it to match any name starting with A. Correction: The = operator compares exact strings; the % wildcard only works with the LIKE keyword: WHERE name LIKE 'A%'.
    • Assuming a table can have only one foreign key: A table can reference multiple other tables by having several foreign keys. For example, an Order table might have a CustomerID foreign key and a ProductID foreign key linking to two different tables.
    Revision Plan
    1. 1Step 1: Learn the jargon – Spend 1–2 days making flashcards or a mind map with definitions for table, record, field, primary key, foreign key, relationship types, and SQL keywords. Use a revision guide or the AQA specification to ensure completeness.
    2. 2Step 2: Get hands-on with SQL – Use an online SQL sandbox (like SQLite Online) or the database tool in your school’s network to practice writing statements. Start with simple SELECT queries, then add WHERE, ORDER BY, and try INSERT, UPDATE, DELETE. Experiment with wildcards and multiple conditions.
    3. 3Step 3: Design practice databases – Take a scenario (e.g., a library or school) and draw out the tables, primary keys, foreign keys, and relationships. Write sample data and then query it on paper. This reinforces how queries relate to structure.
    4. 4Step 4: Tackle past papers – Do as many AQA GCSE database questions as you can. Focus on the specific command words: ‘State’, ‘Explain’, ‘Write an SQL statement’, ‘Design a database’. Mark your answers using the mark scheme and note where you lost marks.
    5. 5Step 5: Teach someone else – Explain the key concepts to a friend or family member. If you can describe primary vs. foreign keys or write a correct SQL query on the whiteboard without notes, you’re exam-ready.
    Exam Question Types
    • 📋E.g., 'What is a primary key?' or 'Define a foreign key.' Provide a precise, technical definition with an example. Use the exact phrasing from the specification for full marks. - Definitions and short-answer
    • 📋You may be given a table schema and asked to 'Write an SQL statement to...' Always match the column names exactly as provided, use correct syntax, and double-check whether sorting or specific columns are required. If unsure, plan the logical steps before writing. - SQL writing
    • 📋Questions might ask you to identify keys from a given table, draw an entity-relationship diagram, or explain the type of relationship between entities. Clearly show which fields are primary and foreign, and justify your choice. - Database design and relationships
    • 📋You might be shown a table and a query, then asked what the output would be. Step through the query condition by condition, ignoring records that don't match the WHERE clause, and only include the columns listed after SELECT. - Interpreting SQL output
    Frequently Asked Questions
    What is the difference between a primary key and a foreign key?
    A primary key is a unique identifier for each record in its own table, and it cannot contain null values. A foreign key is a field in one table that references the primary key of another table to create a link between them. While a primary key ensures entity integrity, a foreign key enforces referential integrity. For example, in a library system, 'BookID' might be the primary key in the Books table, but it appears as a foreign key in the Loans table to show which book was borrowed. A table can have only one primary key, but multiple foreign keys.
    How do I write a SQL query to find all records where a name starts with 'J'?
    Use the LIKE operator with the '%' wildcard: SELECT * FROM table_name WHERE name LIKE 'J%'; The % symbol represents any sequence of characters, so 'J%' matches any string that begins with 'J'. To find names ending with 'son', you'd use '%son'. Remember that LIKE is case-sensitive in some database systems, but for GCSE, assume the exact pattern as given. Always use single quotes around the pattern, and avoid using = with wildcards – this is a common mistake.
    Do I need to use JOIN in my AQA GCSE SQL answers?
    No, the AQA GCSE specification does not explicitly require you to write JOIN statements. However, you may be asked to retrieve data from two related tables by matching the primary key and foreign key in the WHERE clause. For example: SELECT Books.Title, Loans.DateBorrowed FROM Books, Loans WHERE Books.BookID = Loans.BookID; This is known as an implicit join. While you don't need to know JOIN syntax, understanding how to link tables via keys is essential.
    What are the three types of relationships in databases?
    The three types are one-to-one, one-to-many, and many-to-many. A one-to-one relationship means each record in Table A relates to exactly one record in Table B (e.g., a person and their passport). One-to-many occurs when one record in Table A can relate to many records in Table B, but each record in Table B links to only one in Table A (e.g., a customer and their orders). Many-to-many means records in both tables can relate to multiple records in the other; this is typically implemented using a linking table that holds two foreign keys (e.g., students and subjects).
    How can I avoid losing marks on SQL questions in the exam?
    Always read the question carefully: identify the exact columns you need to select, any filtering conditions, and whether sorting is required. Write keywords in uppercase (SELECT, FROM, WHERE) for clarity, use single quotes around text values, and spell table/column names exactly as given. Be mindful of logical operators – use AND when both conditions must be true, OR when either can be true. If you make a minor syntax error, you may still gain partial marks for understanding the logic, so show your reasoning in multi-step questions.