Revision Notes
Cambridge A Level Computer Science (9618): DDL and DML – Revision Notes
Condensed SQL notes on data types, CREATE, ALTER, keys, SELECT, joins, aggregates and data maintenance for Cambridge AS Computer Science 9618 8.3.
- Subject
- Computer Science
- Level
- AS LEVEL
- Topic
- Topic 8: Databases
- Author
- Marlbridge Academic Team
- Updated
- Reviewed by
- Harris Khan (what this means)
Aligned to Cambridge A Level Computer Science (9618), 2026. Official specification .
Syllabus page (what it covers and how it is assessed): Cambridge A Level Computer Science.
Syllabus points this page covers
9618 (AS Level)
- 8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)
Found an error? Report a correction.
Need help with this topic? Request a free trial class for A Level Computer Science (9618).
Quick-recall notes for 8.3 Data Definition Language (DDL) and Data Manipulation Language (DML) (AS content, Paper 1). The DDL and DML study guide builds a full example with results; the DDL and DML practice questions give exam-style practice. Keys and normalisation are in the Database Concepts revision notes.
The big picture
- The DBMS creates and changes structure with its DDL.
- The DBMS runs queries and maintains data with its DML.
- SQL is the industry standard for both.
- Queries in the syllabus use at most two tables.
Syllabus data types
| Type | Holds | Example use |
|---|---|---|
| CHARACTER(n) | Fixed-length text of n characters | Code always 5 characters |
| VARCHAR(n) | Text of up to n characters | Name, address |
| BOOLEAN | TRUE or FALSE | Paid, Member |
| INTEGER | Whole number | Quantity, year |
| REAL | Number with a fractional part | Price, weight |
| DATE | Calendar date | Date of birth |
| TIME | Time of day | Start time |
Phone numbers and codes with leading zeros are text, not INTEGER.
DDL templates
CREATE DATABASE Shop;
CREATE TABLE Product(
ProductID CHARACTER(5),
Name VARCHAR(30),
Price REAL,
InStock BOOLEAN,
PRIMARY KEY (ProductID)
);
CREATE TABLE Sale(
SaleID INTEGER,
ProductID CHARACTER(5),
SaleDate DATE,
Qty INTEGER,
PRIMARY KEY (SaleID),
FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
);
ALTER TABLE Product ADD Supplier VARCHAR(25);
ALTER TABLE Sale ADD PRIMARY KEY (SaleID);
ALTER TABLE Sale ADD FOREIGN KEY (ProductID) REFERENCES Product(ProductID);
Checklist for CREATE TABLE: brackets round the list; a comma after every line except the last; a type for every attribute; size for CHARACTER and VARCHAR; key clauses with field names in brackets.
DML query templates
| Need | SQL |
|---|---|
| Some columns, filtered | SELECT Name, Price FROM Product WHERE Price < 5.00; |
| Two conditions | WHERE Price < 5.00 AND InStock = TRUE |
| Sorted | ORDER BY Name (ascending) or ORDER BY Price DESC |
| Count per group | SELECT Supplier, COUNT(ProductID) FROM Product GROUP BY Supplier; |
| Total per group | SELECT ProductID, SUM(Qty) FROM Sale GROUP BY ProductID; |
| Mean | SELECT AVG(Price) FROM Product; |
| Two tables | SELECT Product.Name, Sale.Qty FROM Sale INNER JOIN Product ON Sale.ProductID = Product.ProductID; |
DML maintenance templates
INSERT INTO Product (ProductID, Name, Price, InStock)
VALUES ('P0042', 'Desk lamp', 14.99, TRUE);
UPDATE Product
SET Price = 12.99
WHERE ProductID = 'P0042';
DELETE FROM Product
WHERE InStock = FALSE;
Order to read a query
- FROM and INNER JOIN … ON: which rows exist
- WHERE: which rows are kept
- GROUP BY: how rows are grouped
- SELECT: which columns, and the aggregates per group
- ORDER BY: the order shown
Reading practice
PRODUCT holds (P01, Pen, 1.20) and (P02, Pad, 2.50). SALE holds (1, P01, Qty 3), (2, P02, Qty 1) and (3, P01, Qty 4).
SELECT Product.Name, SUM(Sale.Qty)
FROM Sale
INNER JOIN Product ON Sale.ProductID = Product.ProductID
GROUP BY Product.Name
ORDER BY Product.Name;
- The join pairs each sale with its product: Pen 3, Pad 1, Pen 4.
- GROUP BY puts the two Pen rows together.
- SUM adds the quantities in each group.
- ORDER BY sorts by name.
Result: Pad 1, then Pen 7. Writing out the joined rows first, as in step 1, avoids most reading errors.
Key terms
| Term | Meaning |
|---|---|
| DDL | Data Definition Language: statements that define or change the structure |
| DML | Data Manipulation Language: statements that query or change the data |
| SQL | Structured Query Language, the industry standard for DDL and DML |
| Aggregate function | Calculates one value from many rows: SUM, COUNT, AVG |
| INNER JOIN | Combines rows from two tables where the ON condition matches |
Exam traps
- ALTER TABLE is DDL, even though it changes something.
- Text and dates in single quotes; numbers and TRUE/FALSE without.
- UPDATE and DELETE without WHERE affect every row.
- In a join, prefix shared attribute names with the table name.
- A group with no rows does not appear in GROUP BY output.
- INSERT values must be in the same order as the attribute list.
- Use exactly the table and attribute names the question gives.
- COUNT counts rows; SUM adds values. For the SALE rows in the reading practice, COUNT(Qty) gives 3 but SUM(Qty) gives 8.
Self-test
- Is CREATE TABLE part of the DDL or the DML?
- State the difference between CHARACTER(6) and VARCHAR(6).
- Choose a data type for (a) a price, (b) whether a fee is paid, (c) a start time.
- Write the clause that makes StaffID the primary key.
- Write SQL to add a field Email of up to 40 characters to the table Staff.
- Write the clause that makes DeptID in Staff a foreign key to Dept.
- Write SQL to list the Surname of every member of Staff with Salary over 30000, in alphabetical order.
- Write SQL to count the staff in each DeptID.
- What is wrong with
SELECT Name FROM Staff WHERE Dept = "Sales";? - Write SQL to delete the staff record with StaffID ‘S017’.
- What happens if
UPDATE Staff SET Salary = 31000;is run? - Name the three DML maintenance statements in the syllabus.
Answers
- DDL.
- CHARACTER(6) always stores exactly 6 characters; VARCHAR(6) stores up to 6.
- (a) REAL (b) BOOLEAN (c) TIME.
PRIMARY KEY (StaffID)ALTER TABLE Staff ADD Email VARCHAR(40);FOREIGN KEY (DeptID) REFERENCES Dept(DeptID)SELECT Surname FROM Staff WHERE Salary > 30000 ORDER BY Surname;SELECT DeptID, COUNT(StaffID) FROM Staff GROUP BY DeptID;- The text value should be in single quotes:
'Sales'. DELETE FROM Staff WHERE StaffID = 'S017';- Every staff record gets a salary of 31000, because there is no WHERE clause.
- INSERT INTO, UPDATE, DELETE FROM.
Related resources
-
Study guides
Cambridge A Level Computer Science (9618): Database Concepts
File-based limits, relational keys, E-R diagrams and normalisation to 3NF with a new worked example, for Cambridge AS Computer Science 9618 section 8.1.
Computer Science · Cambridge · AS Level
Read guide -
Practice questions
Cambridge A Level Computer Science (9618): Database Concepts – Practice Questions
Original questions with mark-scheme answers on keys, relationships, E-R diagrams and normalising to 3NF for Cambridge AS Computer Science 9618.
Computer Science · Cambridge · AS Level
Try questions -
Revision notes
Cambridge A Level Computer Science (9618): Database Concepts – Revision Notes
Condensed notes on file-based limits, keys, relationships, E-R diagrams and 1NF to 3NF for Cambridge AS Computer Science 9618 8.1, with a self-test.
Computer Science · Cambridge · AS Level
Revise topic
Get free revision emails (optional)
Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.