Structured Query Language (SQL) — AQA A-Level Computer Science
Structured Query Language (SQL) is a declarative language designed for defining, manipulating, and querying data within relational database management systems. For AQA A-Level Computer Science, students must master both Data Definition Language (DDL) operations like table creation and Data Manipulation Language (DML) commands including complex multi-table queries.
Structured Query Language (SQL) explained
This statement asks you to write SQL that works across more than one table and performs all four core data operations: retrieve (SELECT), update (UPDATE), insert (INSERT) and delete (DELETE).
Read the full explanation
For retrieval across tables, you join them on a shared key, for example SELECT Customer.Name, Orders.OrderDate FROM Customer INNER JOIN Orders ON Customer.CustomerID = Orders.CustomerID; The join condition matches a foreign key to its primary key, which is how a relational database links related records. For updates and deletes you must identify the correct rows with a WHERE clause, because omitting it affects every row in the table. An UPDATE that changes a price for one product is written UPDATE Product SET Price = 9.99 WHERE ProductID = 103; and a DELETE is written DELETE FROM Orders WHERE OrderID = 5012;.
Your focus
- Be able to use SQL to retrieve, update, insert and delete data from multiple tables of a relational database.
Structured Query Language (SQL) exam tips
Topic Overview
Structured Query Language (SQL) is the global standard declarative language used to manage, query, and maintain relational databases. Unlike procedural programming languages, SQL specifies what data must be retrieved or modified rather than detailing the step-by-step algorithms required to process it.
Within the AQA A-Level specification, SQL is divided into Data Definition Language (DDL) commands for schema design and Data Manipulation Language (DML) commands for operational data processing. Mastering SQL provides the foundational skillset required for backend software development, database administration, and Paper 2 database architecture assessment.
Key Concepts
- →Declarative paradigm: SQL code defines the required outputs and logical constraints without specifying execution control flows.
- →Data Definition Language (DDL): Statements such as CREATE TABLE, ALTER TABLE, and DROP TABLE that establish database schema, data types, and integrity constraints.
- →Data Manipulation Language (DML): Statements including SELECT, INSERT INTO, UPDATE, and DELETE used to query and modify records.
- →Relational join operations: Combining data across multiple tables using primary key and foreign key equivalences in WHERE or INNER JOIN clauses.
- →Aggregation and grouping: Utilizing aggregate functions (COUNT, SUM, AVG, MIN, MAX) in conjunction with GROUP BY and HAVING clauses.
Marking Points
- Writes a SELECT statement that joins two tables on matching primary and foreign key columns.
- Uses a WHERE clause in every UPDATE and DELETE so only the intended rows change.
- Names the table and the columns correctly in an INSERT, with values matching the column order.
- Recognises that a child-table row must reference a key that already exists in the parent table.
- Identifies which rows a given statement will affect by reasoning through the sample data.
Examiner Tips
- 💡Read each SQL statement and state the exact rows it will affect before selecting an answer.
- 💡When choosing between UPDATE and INSERT, check whether the record already exists.
- 💡Check the join condition uses the correct key pair from the table definitions given in the question.
- 💡Always write SQL keywords in UPPERCASE (e.g., SELECT, FROM, WHERE, ORDER BY) to improve readability and ensure clarity for the examiner.
- 💡Qualify column names with their respective table name (e.g., Student.StudentID) whenever a column exists in more than one table in your query.
- 💡Double-check commas in CREATE TABLE statements; missing commas between column definitions or putting a comma before the closing bracket is a frequent syntax slip.
Common Mistakes
- Omits the WHERE clause from an UPDATE or DELETE, which changes or removes every row; add a condition that identifies the intended rows.
- Joins tables on columns that are not related keys, producing meaningless combinations; join on the foreign key matching the primary key.
- Inserts a foreign key value that has no matching parent record, breaking referential integrity; insert the parent row first or use an existing key.
- Believing SQL is an imperative or procedural programming language; SQL is declarative because the query optimiser determines the retrieval algorithm, not the programmer.
- Using the WHERE clause instead of the HAVING clause when filtering aggregated data groups created by GROUP BY.
- Assuming strings can be unquoted; string and date literals must always be enclosed in single or standard quotation marks, unlike numeric values.
Revision Plan
- 1Day 1-3: Master basic DML syntax by writing single-table SELECT, INSERT, UPDATE, and DELETE queries.
- 2Day 4-6: Practice multi-table queries involving primary-to-foreign key relationships and aggregate functions using GROUP BY and HAVING.
- 3Day 7-9: Learn DDL commands by writing CREATE TABLE and ALTER TABLE scripts with comprehensive primary and foreign key constraints.
- 4Day 10-12: Complete past AQA Paper 2 database exam questions under timed conditions and review against official mark schemes.
Exam Question Types
- 📋Writing multi-table SELECT queries with filtering, sorting, and aggregate functions based on an entity-relationship scenario.
- 📋Writing DDL scripts to create relational tables complete with specified data types, primary keys, and foreign keys.
- 📋Updating or deleting existing records matching specific conditions using UPDATE ... SET or DELETE FROM statements.
- 📋Tracing or explaining the output table returned by a provided SQL statement applied to sample data.
Command Word Expectations (AQA)
Formulate syntactically accurate SQL code that satisfies all criteria and constraints specified in the scenario without procedural code.
Set out the logical operation of an SQL clause, constraint, or command, making clear relationships between relational theory and query outcome.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A relational database contains two tables: Doctor (DoctorID, DoctorName, Specialism) Appointment (AppointmentID, DoctorID, PatientName, AppDate, Fee) Write an SQL query to display the DoctorName, PatientName, and Fee for all appointments scheduled on '2025-10-15' where the Fee is greater than 50.00. The results should be ordered by Fee in descending order.
- 1.Step 1: Identify required output fields: Doctor.DoctorName, Appointment.PatientName, Appointment.Fee for the SELECT clause.
- 2.Step 2: Identify tables involved: Doctor and Appointment for the FROM clause.
- 3.Step 3: Establish the join condition: Doctor.DoctorID = Appointment.DoctorID.
- 4.Step 4: Add filtering criteria: AppDate = '2025-10-15' AND Fee > 50.00 in the WHERE clause.
- 5.Step 5: Apply sorting constraint: ORDER BY Fee DESC.
Question: Write an SQL statement to create a table named 'Module' with the following attributes: - ModuleCode: fixed-length string of 6 characters, Primary Key - Title: variable-length string up to 50 characters, cannot be empty - Credits: integer value - DepartmentID: integer value, referencing DepartmentID in the Department table as a Foreign Key.
- 1.Step 1: Begin with the DDL statement CREATE TABLE Module ( ... ).
- 2.Step 2: Define ModuleCode as CHAR(6) and specify PRIMARY KEY constraint.
- 3.Step 3: Define Title as VARCHAR(50) and add the NOT NULL constraint.
- 4.Step 4: Define Credits as INT or INTEGER.
- 5.Step 5: Define DepartmentID as INT or INTEGER and specify the foreign key constraint referencing Department(DepartmentID).