Structured query language (SQL) — AQA GCSE Computer Science
Verified courseTeaching note checked against the official specification.
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.
Your focus
- Select UPDATE or DELETE correctly for a described editing or deletion task.
- Write an UPDATE statement that sets one or more columns to new values for the rows matching a WHERE condition.
- 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
- 1Day 1-3: Practice basic data retrieval queries using SELECT, FROM, and WHERE on simple single-table schemas.
- 2Day 4-6: Master compound conditions using AND/OR operators, pattern matching, and sorting results using ORDER BY.
- 3Day 7-9: Learn and practice modification queries: INSERT INTO, UPDATE, and DELETE FROM, paying special attention to WHERE clauses in UPDATE/DELETE.
- 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)
Construct fully formed, syntactically valid SQL statements matching the exact fields, conditions, and table names specified in the prompt.
Provide the exact data items, record counts, or attribute names returned by a given SQL query without extensive justification.
Pick out errors, suitable primary keys, or appropriate SQL keywords required to achieve a described database manipulation.
How Students Lose Marks (Examiner Pitfalls)
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.Step 1: Identify the requested fields for the SELECT clause: FirstName, LastName, Attendance.
- 2.Step 2: Identify the source table name for the FROM clause: tblPupils.
- 3.Step 3: Construct the filtering condition for the WHERE clause using boolean AND: YearGroup = 11 AND Attendance < 90.0.
- 4.Step 4: Add the ordering criteria using the ORDER BY clause: Attendance ASC (ASC is default but good practice to state).
- 5.Step 5: Assemble the complete query in strict SQL syntax order.
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.Step 1: Identify the modification command: UPDATE tblBooks.
- 2.Step 2: Specify the new value using the SET clause: SET Available = False.
- 3.Step 3: Define the condition using the WHERE clause so that only the specified record is modified: WHERE BookID = 'BK104'.
- 4.Step 4: Combine the parts into a single coherent SQL command.