Skip to topic
    ← Back to course topics

    Structured query language (SQL) — AQA GCSE Computer Science

    Structured Query Language (SQL) is a standardised declarative language used to create, query, and manipulate relational databases. In AQA GCSE Computer Science, students must master data retrieval using SELECT, FROM, and WHERE clauses, alongside updating, inserting, and deleting records.

    Structured query language (SQL) explained

    SQL is the language used to work with relational databases.

    Read the full explanation

    Editing means changing values already stored in existing records, which is done with UPDATE ... SET ... WHERE. Deleting means removing whole records (rows) from a table, which is done with DELETE FROM ... WHERE. Both commands act on the rows that satisfy the WHERE condition, so the condition is the safety catch: without it, UPDATE changes every row and DELETE empties the table. For example, in a table Student with columns StudentID, Name and Year, the statement UPDATE Student SET Year = 11 WHERE StudentID = 42 changes one learner's year group, while DELETE FROM Student WHERE StudentID = 42 removes that one record. Neither command changes the table's structure; adding or removing columns is a different job.

    Read the Structured query language (SQL) study guideFull revision notes for AQA GCSE Computer Science

    Your focus

    1. Select UPDATE or DELETE correctly for a described editing or deletion task.
    2. Write an UPDATE statement that sets one or more columns to new values for the rows matching a WHERE condition.
    3. Write a DELETE FROM statement that removes only the records matching a stated WHERE condition.

    Which command word is this?

    Construct fully formed, syntactically valid SQL statements matching the exact fields, conditions, and table names specified in the prompt.

    Structured query language (SQL) exam tips

    Topic Overview

    Structured Query Language (SQL) is the international standard language used to interact with relational databases. For AQA GCSE Computer Science, students are required to write and interpret standard SQL statements to query databases and modify data across structured tables.

    Mastering SQL helps students understand how persistent data storage works in commercial computer systems, from website backends to enterprise resource planning software. It directly links Paper 2 programming and data representation topics to real-world software engineering contexts.

    Key Concepts
    • →Core Data Retrieval: The SELECT ... FROM ... WHERE structure provides the baseline syntax for querying records and extracting specific attributes.
    • →Wildcard Searches: Using '*' selects every column in a table, whereas comparison operators (=, <, >, <=, >=, != or <>) filter specific records.
    • →Logical Operators: Combining multiple filter conditions using AND, OR, and NOT within the WHERE clause to narrow or broaden query results.
    • →Sorting Results: The ORDER BY clause allows output to be arranged in ASC (ascending) or DESC (descending) order based on one or more attributes.
    • →Data Modification: Using INSERT INTO ... VALUES, UPDATE ... SET ... WHERE, and DELETE FROM ... WHERE to manipulate stored records.
    Marking Points
    • UPDATE is the command that edits existing data values in a table; it does not create new records or new tables.
    • SET lists the column or columns being changed and the new value for each, for example SET Year = 11.
    • DELETE FROM removes whole records (rows) from a named table rather than blanking individual field values.
    • A WHERE clause restricts which rows are affected; omitting it means every row in the table is edited or deleted.
    • Choosing the correct command for the task: changing a stored value uses UPDATE, removing a record uses DELETE.
    • The table name follows the command (UPDATE table_name / DELETE FROM table_name) and identifies which table is affected.
    Examiner Tips
    • 💡Read the scenario and decide first whether a value is being changed (UPDATE) or a record is being removed (DELETE), then write the command.
    • 💡Always include a WHERE clause that pins down the single record or group of records named in the question.
    • 💡Check the column names and table name against any table given in the question and copy them exactly.
    • 💡For a multiple-choice question, eliminate options that omit WHERE or that use the wrong command for the task described.
    • 💡Always check whether the question asks for 'all fields' or specific attributes. If specific, do not use 'SELECT *' as this will lose an attribute specification mark.
    • 💡Double-check boolean string matching; ensure text values match the exact spelling and casing given in the question prompt and are encased in quotation marks.
    • 💡Write SQL keywords in UPPERCASE (e.g., SELECT, FROM, WHERE). Although many database engines are case-insensitive, writing keywords in capitals makes your script unambiguous to the examiner.
    Common Mistakes
    • Using UPDATE to remove a record: UPDATE changes values in existing rows, whereas removing a record needs DELETE FROM with a WHERE condition.
    • Leaving out the WHERE clause: this edits or deletes every row in the table, so always state the condition that identifies the intended record.
    • Confusing DELETE with removing a column or the whole table: DELETE FROM removes rows of data, not the table's structure.
    • Writing SET before naming the table, or placing WHERE before SET: the order is command, table name, SET assignments, then WHERE condition.
    • Thinking WHERE is used to select columns: Students often confuse SELECT (which filters columns/attributes) with WHERE (which filters rows/records).
    • Forgetting quotes around text literals: In SQL conditions, alphanumeric string literals must be wrapped in single or double quotes, whereas numeric literals must not.
    • Assuming table names are specified in SELECT: The SELECT clause specifies field headers only; the table itself is exclusively defined in the FROM clause.
    Revision Plan
    1. 1Day 1-3: Practice basic data retrieval queries using SELECT, FROM, and WHERE on simple single-table schemas.
    2. 2Day 4-6: Master compound conditions using AND/OR operators, pattern matching, and sorting results using ORDER BY.
    3. 3Day 7-9: Learn and practice modification queries: INSERT INTO, UPDATE, and DELETE FROM, paying special attention to WHERE clauses in UPDATE/DELETE.
    4. 4Day 10-14: Work through AQA past paper exam questions, writing syntax by hand to avoid reliance on IDE auto-completion.
    Exam Question Types
    • 📋Write an SQL statement: Providing a table schema and asking you to write a complete query to display specific fields under set conditions.
    • 📋Predict the output: Presenting an existing database table and an SQL query, asking you to draw the resulting record set.
    • 📋Identify errors/syntax correction: Providing an SQL statement with logical or structural bugs and asking you to rewrite it correctly.
    Command Word Expectations (AQA)
    Write

    Construct fully formed, syntactically valid SQL statements matching the exact fields, conditions, and table names specified in the prompt.

    State

    Provide the exact data items, record counts, or attribute names returned by a given SQL query without extensive justification.

    Identify

    Pick out errors, suitable primary keys, or appropriate SQL keywords required to achieve a described database manipulation.

    How Students Lose Marks (Examiner Pitfalls)
    Pitfall: Confusing the wildcard asterisk '*' in the SELECT statement with the wildcard '%' or '*' in WHERE search patterns.
    ❌ Weak Answer (Loses Marks):SELECT * WHERE Surname = *
    Example improved answer:SELECT * FROM Students WHERE Surname LIKE 'S%'
    Examiner Tip: Remember that SELECT * retrieves all fields/columns, while pattern matching inside a WHERE condition requires the LIKE operator and specific wildcards (typically % in standard SQL or * in Microsoft Access variants; AQA standardly accepts % or * depending on the engine context, but standard SQL uses %).
    Pitfall: Omitting the FROM clause or writing SQL clauses out of their mandatory logical order (SELECT, FROM, WHERE, ORDER BY).
    ❌ Weak Answer (Loses Marks):SELECT Forename, Surname WHERE Age >= 16 FROM Students
    Example improved answer:SELECT Forename, Surname FROM Students WHERE Age >= 16
    Examiner Tip: Always write your SQL commands in the strict sequence: SELECT (fields), FROM (table), WHERE (criteria), ORDER BY (sort). Swapping FROM and WHERE loses the query structure mark.
    Step-by-Step Worked Solutions

    Question: A school maintains a database table called 'tblPupils' with the following fields: PupilID (integer), FirstName (text), LastName (text), YearGroup (integer), Attendance (real). Write an SQL query to retrieve the FirstName, LastName, and Attendance of all pupils in YearGroup 11 whose Attendance is below 90.0, sorted in ascending order of Attendance.

    1. 1.Step 1: Identify the requested fields for the SELECT clause: FirstName, LastName, Attendance.
    2. 2.Step 2: Identify the source table name for the FROM clause: tblPupils.
    3. 3.Step 3: Construct the filtering condition for the WHERE clause using boolean AND: YearGroup = 11 AND Attendance < 90.0.
    4. 4.Step 4: Add the ordering criteria using the ORDER BY clause: Attendance ASC (ASC is default but good practice to state).
    5. 5.Step 5: Assemble the complete query in strict SQL syntax order.
    Final Answer: SELECT FirstName, LastName, Attendance FROM tblPupils WHERE YearGroup = 11 AND Attendance < 90.0 ORDER BY Attendance ASC;

    Question: A library database contains a table named 'tblBooks' with fields: BookID, Title, Author, Genre, and Available (Boolean). Write an SQL statement to update the 'Available' status of the book with BookID 'BK104' to False.

    1. 1.Step 1: Identify the modification command: UPDATE tblBooks.
    2. 2.Step 2: Specify the new value using the SET clause: SET Available = False.
    3. 3.Step 3: Define the condition using the WHERE clause so that only the specified record is modified: WHERE BookID = 'BK104'.
    4. 4.Step 4: Combine the parts into a single coherent SQL command.
    Final Answer: UPDATE tblBooks SET Available = False WHERE BookID = 'BK104';
    Active Recall Memory Test
    Which SQL clause determines which fields (columns) are displayed in the query output?
    Key Fact: The SELECT clause.
    Which SQL keyword is used to filter records (rows) based on specific criteria?
    Key Fact: The WHERE keyword.
    What happens if an UPDATE or DELETE command is executed without a WHERE clause?
    Key Fact: The update or deletion will apply to every single record in the entire table.
    Which keyword specifies that query results should be sorted from highest to lowest?
    Key Fact: DESC (descending).
    Frequently Asked Questions
    Do I need to memorise SQL joins for AQA GCSE Computer Science?
    No, multi-table JOIN operations are not part of the core AQA GCSE Computer Science specification. You are only required to query and manipulate data from a single database table at this level.
    Does capitalisation matter when writing SQL keywords in the exam?
    SQL syntax itself is case-insensitive, meaning 'select' works the same as 'SELECT'. However, examiners strongly recommend writing SQL keywords in UPPERCASE and table/field names as given in the paper to ensure clarity and avoid ambiguity.
    Do I need to put a semicolon at the end of my SQL statement in the exam?
    While standard SQL uses a semicolon to terminate statements, AQA mark schemes generally do not penalise students for omitting the trailing semicolon. However, including it demonstrates good syntax discipline.
    What is the difference between SELECT * and SELECT fieldname?
    SELECT * uses the asterisk as a wildcard to return every single column available in the table. In contrast, SELECT fieldname only returns that specific column, reducing unnecessary data output.