A pencil-and-paper workbook: ask the table questions on paper first, learn the SQL, then design and defend your data.
Before you write any SQL you can already ask a table questions in plain English: show only these rows, put them in this order, count them. SQL is simply those questions written in a short, strict form that a database understands.
| LearnerID PK | Surname | Name | Grade | Sport | Cell | BirthDate | Mark |
|---|---|---|---|---|---|---|---|
| 1 | Dlamini | Thandi | 12 | Netball | 0821234567 | 2007/03/14 | 78 |
| 2 | Pillay | Ryan | 11 | Rugby | 0839876543 | 2008/07/02 | 64 |
| 3 | Mokoena | Naledi | 12 | Netball | 2007/11/23 | 91 | |
| 4 | Botha | Anke | 10 | Hockey | 0716543210 | 2009/01/30 | 55 |
| 5 | Khumalo | Sipho | 11 | Soccer | 0825551122 | 2008/05/19 | 82 |
| 6 | Adams | Zaid | 12 | Soccer | 2007/09/08 | 47 | |
| 7 | Naidoo | Priya | 10 | Netball | 0794443321 | 2009/04/11 | 73 |
| 8 | Jacobs | Liam | 11 | Rugby | 0612228899 | 2008/12/05 | 69 |
| 9 | Sithole | Lerato | 12 | Hockey | 0845557788 | 2007/06/27 | 86 |
| 10 | Petersen | Chante | 10 | Chess | 0763330099 | 2009/08/16 | 60 |
| Keyword | Means | Compulsory? |
|---|---|---|
| SELECT | which fields (columns) to show | yes |
| FROM | which table to use | yes |
| WHERE | keep only the rows that pass a test | no |
| ORDER BY | sort the rows (ASC = small to big, the default; DESC = big to small) | no |
SELECT Surname, Mark FROM tblLearner WHERE Grade = 12 ORDER BY Mark DESC;
SELECT * FROM tblLearner WHERE Sport = "Hockey"; SELECT Surname, Grade FROM tblLearner ORDER BY Grade DESC, Surname;
SELECT DISTINCT Sport FROM tblLearner ORDER BY Sport;
| LearnerID PK | Surname | Name | Grade | Sport | Cell | BirthDate | Mark |
|---|---|---|---|---|---|---|---|
| 1 | Dlamini | Thandi | 12 | Netball | 0821234567 | 2007/03/14 | 78 |
| 2 | Pillay | Ryan | 11 | Rugby | 0839876543 | 2008/07/02 | 64 |
| 3 | Mokoena | Naledi | 12 | Netball | 2007/11/23 | 91 | |
| 4 | Botha | Anke | 10 | Hockey | 0716543210 | 2009/01/30 | 55 |
| 5 | Khumalo | Sipho | 11 | Soccer | 0825551122 | 2008/05/19 | 82 |
| 6 | Adams | Zaid | 12 | Soccer | 2007/09/08 | 47 | |
| 7 | Naidoo | Priya | 10 | Netball | 0794443321 | 2009/04/11 | 73 |
| 8 | Jacobs | Liam | 11 | Rugby | 0612228899 | 2008/12/05 | 69 |
| 9 | Sithole | Lerato | 12 | Hockey | 0845557788 | 2007/06/27 | 86 |
| 10 | Petersen | Chante | 10 | Chess | 0763330099 | 2009/08/16 | 60 |
Using the table in Think First 1.1, write a query that shows the Surname and Sport of every learner in Grade 11.
Show the Surname and Mark of the netball players, sorted by surname from A to Z. Write the result.
| Surname | Mark |
|---|---|
Write a query that lists the different sports, each once only, in alphabetical order.
Work through the query on the table above, then write the rows that appear.
SELECT Surname, Mark FROM tblLearner WHERE Sport = "Soccer" ORDER BY Mark DESC;
| Surname | Mark |
|---|---|
Each query has one mistake. Say what it is.
1. SELECT Surname, Mark tblLearner WHERE Grade = 12; 2. SELECT Surname FROM tblLearner WHERE Sport = Netball; 3. SELECT Surname, FROM tblLearner; 4. SELECT Surname FROM tblLearner ORDER BY Mark DESC WHERE Grade = 12;
One test is rarely enough. AND, OR and NOT combine tests; LIKE finds patterns; IN, BETWEEN and IS NULL are shortcuts for common tests; dates need their own symbol. You will practise on paper until you can predict exactly which rows come back.
| LearnerID PK | Surname | Name | Grade | Sport | Cell | BirthDate | Mark |
|---|---|---|---|---|---|---|---|
| 1 | Dlamini | Thandi | 12 | Netball | 0821234567 | 2007/03/14 | 78 |
| 2 | Pillay | Ryan | 11 | Rugby | 0839876543 | 2008/07/02 | 64 |
| 3 | Mokoena | Naledi | 12 | Netball | 2007/11/23 | 91 | |
| 4 | Botha | Anke | 10 | Hockey | 0716543210 | 2009/01/30 | 55 |
| 5 | Khumalo | Sipho | 11 | Soccer | 0825551122 | 2008/05/19 | 82 |
| 6 | Adams | Zaid | 12 | Soccer | 2007/09/08 | 47 | |
| 7 | Naidoo | Priya | 10 | Netball | 0794443321 | 2009/04/11 | 73 |
| 8 | Jacobs | Liam | 11 | Rugby | 0612228899 | 2008/12/05 | 69 |
| 9 | Sithole | Lerato | 12 | Hockey | 0845557788 | 2007/06/27 | 86 |
| 10 | Petersen | Chante | 10 | Chess | 0763330099 | 2009/08/16 | 60 |
SELECT Surname FROM tblLearner WHERE (Sport = "Netball" OR Sport = "Hockey") AND Grade = 12;
| Test | Meaning | Example |
|---|---|---|
| LIKE | matches a pattern. % stands for any number of characters (even none); _ stands for exactly one character | Surname LIKE "S%" starts with S Surname LIKE "%a" ends in a Surname LIKE "%ai%" contains ai |
| IN | equal to any value in a list (a short way of writing several ORs) | Grade IN (10, 12) |
| BETWEEN | from a small value to a big one, both ends included | Mark BETWEEN 60 AND 80 |
| IS NULL | the field is empty. Never write = NULL: it matches nothing, ever | Cell IS NULL Cell IS NOT NULL |
| #date# | a date is surrounded by # signs and written year first, so that it cannot be mixed up with day and month | BirthDate >= #2008/01/01# |
Write the surnames in the table above that match each pattern. (The pattern is not case sensitive.)
| Condition | Surnames that match |
|---|---|
| Surname LIKE "S%" | |
| Surname LIKE "%a" | |
| Surname LIKE "_a%" | |
| Surname LIKE "%ai%" | |
| Surname LIKE "%o%o%" |
Write the rows that appear.
SELECT Surname, Grade, Sport FROM tblLearner WHERE Sport = "Netball" OR Sport = "Hockey" AND Grade = 12;
| Surname | Grade | Sport |
|---|---|---|
Only the brackets have changed. Write the rows that appear. Why is there one row fewer?
SELECT Surname, Grade, Sport FROM tblLearner WHERE (Sport = "Netball" OR Sport = "Hockey") AND Grade = 12;
| Surname | Grade | Sport |
|---|---|---|
Write the rows that appear. A row appears if it passes either test.
SELECT Surname, BirthDate FROM tblLearner WHERE Cell IS NULL OR BirthDate < #2007/07/01#;
| Surname | BirthDate |
|---|---|
Show the Surname, Grade and Sport of learners in Grade 11 or 12 who play rugby or soccer. Use IN for the grades and brackets round the sports.
Show the Surname and BirthDate of learners born from 1 January 2007 to 30 June 2007.
Each of these queries runs without an error, yet returns no rows from tblLearner. Say why, and write the corrected condition.
1. WHERE Cell = NULL 2. WHERE Mark BETWEEN 80 AND 60 3. WHERE Surname LIKE "S" 4. WHERE Grade = 10 AND Grade = 12
SQL can calculate as well as filter. It can work out a new column for every row, boil a whole column down to one number, and cut text and dates into pieces. In this unit you will find those answers by hand first, so you know what the database is doing.
| ProductID PK | ProdName | Category | Price | Stock |
|---|---|---|---|---|
| 1 | Brown bread | Bakery | 16.50 | 30 |
| 2 | Full-cream milk 1L | Dairy | 19.99 | 18 |
| 3 | Maize meal 5kg | Staples | 54.90 | 12 |
| 4 | Candles (6) | Load shedding | 24.00 | 40 |
| 5 | Eggs (dozen) | Dairy | 49.50 | 9 |
| 6 | Rechargeable lamp | Load shedding | 129.00 | 0 |
| 7 | Sugar 2kg | Staples | 38.00 | 25 |
| 8 | Matches | Load shedding | 6.50 | 60 |
SELECT ProdName, Price * Stock AS StockValue FROM tblProduct ORDER BY StockValue DESC; SELECT Surname & ", " & Name AS FullName FROM tblLearner;
| Function | Gives | Example |
|---|---|---|
| SUM(field) | the total | SUM(Stock) |
| MIN(field) | the smallest value | MIN(Price) |
| MAX(field) | the biggest value | MAX(Price) |
| AVG(field) | the average | AVG(Mark) |
| COUNT(*) | the number of rows | COUNT(*) |
SELECT COUNT(*) AS NumDear FROM tblProduct WHERE Price > 20; SELECT MIN(Price) AS Cheapest, MAX(Price) AS Dearest FROM tblProduct; SELECT TOP 3 ProdName, Price FROM tblProduct ORDER BY Price DESC;
| Function | What it does | Example | Gives |
|---|---|---|---|
| ROUND(x, n) | rounds to n decimal places | ROUND(17.991, 1) | 18 |
| INT(x) | keeps the whole part (rounds down) | INT(17.991) | 17 |
| LEN(text) | number of characters | LEN("Naledi") | 6 |
| LEFT(text, n) | the first n characters | LEFT("Mokoena", 3) | Mok |
| RIGHT(text, n) | the last n characters | RIGHT("0821234567", 4) | 4567 |
| MID(text, start, n) | n characters from position start (the first character is position 1) | MID("0821234567", 4, 3) | 123 |
| FORMAT(x, “R0.00”) | shows a number in a set layout | FORMAT(16.5, "R0.00") | R16.50 |
| YEAR / MONTH / DAY(date) | one part of a date as a number | YEAR(#2007/03/14#) MONTH(#2007/03/14#) DAY(#2007/03/14#) | 2007 3 14 |
| Date() | today's date | YEAR(Date()) - YEAR(BirthDate) | the age this year |
Work out the single value that each query gives. Use the stock list in Think First.
| Query | Result |
|---|---|
| SELECT COUNT(*) FROM tblProduct WHERE Category = "Load shedding" | |
| SELECT SUM(Stock) FROM tblProduct | |
| SELECT MAX(Price) FROM tblProduct WHERE Category = "Dairy" | |
| SELECT MIN(Stock) FROM tblProduct WHERE Stock > 0 | |
| SELECT ROUND(AVG(Price), 2) FROM tblProduct | |
| SELECT SUM(Price * Stock) FROM tblProduct WHERE Category = "Staples" |
Write a query that shows the ProdName of every Load shedding product and a column called SalePrice: the price with 10% off, rounded to 2 decimals.
Today is 28 October 2026. For the netball players, show one column called ShortName (the first letter of the name, a full stop and space, then the surname, as in T. Dlamini) and a column called Age (this year minus the birth year).
Work out what each expression gives for the stated learner or product (see the tables in Units 2 and 3).
| Expression | For | Result |
|---|---|---|
| LEN(Surname) | the learner with LearnerID 3 | |
| LEFT(Sport, 3) | LearnerID 7 | |
| RIGHT(Cell, 4) | LearnerID 5 | |
| MID(Cell, 4, 3) | LearnerID 5 | |
| INT(Mark / 10) | LearnerID 3 | |
| MONTH(BirthDate) | LearnerID 8 | |
| FORMAT(Price, "R0.00") | ProductID 2 |
Show the Surname and Mark of the three learners with the highest marks.
Sometimes you want an answer for every group: the number of learners in each sport, the sales of every product. GROUP BY does that. Then you will join two tables, so that a sale shows the name of the product instead of a number, and meet the most common mistake in a join.
| Surname | Sport | Mark |
|---|---|---|
| Dlamini | Netball | 78 |
| Pillay | Rugby | 64 |
| Mokoena | Netball | 91 |
| Botha | Hockey | 55 |
| Khumalo | Soccer | 82 |
| Adams | Soccer | 47 |
| Naidoo | Netball | 73 |
| Jacobs | Rugby | 69 |
| Sithole | Hockey | 86 |
| Petersen | Chess | 60 |
| Sport | Cards in the pile | Total of the marks | Average mark (1 decimal) |
|---|---|---|---|
| Order of work | Clause | What it does |
|---|---|---|
| 1 | FROM | take the table |
| 2 | WHERE | throw away single rows |
| 3 | GROUP BY | make the groups |
| 4 | HAVING | throw away whole groups |
| 5 | SELECT | work out the columns and aggregates |
| 6 | ORDER BY | sort the result |
SELECT Sport, COUNT(*) AS Num, ROUND(AVG(Mark), 1) AS AvgMark FROM tblLearner WHERE Grade >= 11 GROUP BY Sport HAVING COUNT(*) >= 2 ORDER BY Sport;
Follow the order of work: first throw away the rows that fail WHERE, then make the groups, then throw away the groups that fail HAVING. Write the result.
SELECT Sport, ROUND(AVG(Mark), 1) AS AvgMark FROM tblLearner WHERE Grade >= 11 GROUP BY Sport HAVING COUNT(*) >= 2;
| Sport | AvgMark |
|---|---|
| ProductID PK | ProdName | Category | Price | Stock |
|---|---|---|---|---|
| 1 | Brown bread | Bakery | 16.50 | 30 |
| 2 | Full-cream milk 1L | Dairy | 19.99 | 18 |
| 3 | Maize meal 5kg | Staples | 54.90 | 12 |
| 4 | Candles (6) | Load shedding | 24.00 | 40 |
| 5 | Eggs (dozen) | Dairy | 49.50 | 9 |
| 6 | Rechargeable lamp | Load shedding | 129.00 | 0 |
| 7 | Sugar 2kg | Staples | 38.00 | 25 |
| 8 | Matches | Load shedding | 6.50 | 60 |
| SaleID PK | ProductID | Qty | SaleDate |
|---|---|---|---|
| 101 | 1 | 3 | 2026/10/01 |
| 102 | 4 | 2 | 2026/10/01 |
| 103 | 2 | 1 | 2026/10/02 |
| 104 | 4 | 5 | 2026/10/02 |
| 105 | 8 | 10 | 2026/10/03 |
| 106 | 1 | 2 | 2026/10/03 |
| 107 | 3 | 1 | 2026/10/04 |
| 108 | 6 | 1 | 2026/10/05 |
| 109 | 2 | 4 | 2026/10/05 |
| 110 | 4 | 1 | 2026/10/06 |
SELECT tblSale.SaleID, tblProduct.ProdName, tblSale.Qty FROM tblSale, tblProduct WHERE tblSale.ProductID = tblProduct.ProductID AND tblProduct.Category = "Load shedding"; SELECT S.SaleID, P.ProdName, S.Qty * P.Price AS Amount FROM tblSale S, tblProduct P WHERE S.ProductID = P.ProductID;
| CoachID PK | CoachName |
|---|---|
| 1 | Mr Adams |
| 2 | Mrs Botha |
| TeamID PK | TeamName | CoachID |
|---|---|---|
| 1 | U14 Netball | 2 |
| 2 | U16 Soccer | 1 |
| 3 | U15 Hockey | 2 |
| CoachName | TeamName |
|---|---|
| Mr Adams | U14 Netball |
| Mr Adams | U16 Soccer |
| Mr Adams | U15 Hockey |
| Mrs Botha | U14 Netball |
| Mrs Botha | U16 Soccer |
| Mrs Botha | U15 Hockey |
| CoachName | TeamName |
|---|---|
| Mrs Botha | U14 Netball |
| Mr Adams | U16 Soccer |
| Mrs Botha | U15 Hockey |
Work out the rows (the tables are on this page). Write the result.
SELECT tblSale.SaleID, tblProduct.ProdName, tblSale.Qty FROM tblSale, tblProduct WHERE tblSale.ProductID = tblProduct.ProductID AND tblProduct.Category = "Load shedding" ORDER BY tblSale.SaleID;
| SaleID | ProdName | Qty |
|---|---|---|
First match each sale to its product, then group by category. Write the result.
SELECT P.Category, SUM(S.Qty) AS TotalSold FROM tblSale S, tblProduct P WHERE S.ProductID = P.ProductID GROUP BY P.Category;
| Category | TotalSold |
|---|---|
Write a query that shows each product name and the money it brought in (Qty × Price added up, called Income), but only for products that brought in more than R100, the biggest income first. Join the tables with WHERE and use the aliases S and P.
Each query has one fault. Say what is wrong.
1. SELECT ProdName, Qty
FROM tblSale, tblProduct
WHERE tblProduct.Category = "Dairy";
2. SELECT ProductID, ProdName
FROM tblSale S, tblProduct P
WHERE S.ProductID = P.ProductID;
3. SELECT P.Category, SUM(S.Qty) AS TotalSold
FROM tblSale S, tblProduct P
WHERE S.ProductID = P.ProductID
GROUP BY P.Category
HAVING TotalSold > 4;SELECT only looks at data. INSERT, UPDATE and DELETE change it, and a missing WHERE can ruin a whole table. Then you will learn how Delphi sends SQL to the database through a TADOQuery, including a value typed by the user.
| ProductID PK | ProdName | Category | Price | Stock |
|---|---|---|---|---|
| 1 | Brown bread | Bakery | 16.50 | 30 |
| 2 | Full-cream milk 1L | Dairy | 19.99 | 18 |
| 3 | Maize meal 5kg | Staples | 54.90 | 12 |
| 4 | Candles (6) | Load shedding | 24.00 | 40 |
| 5 | Eggs (dozen) | Dairy | 49.50 | 9 |
| 6 | Rechargeable lamp | Load shedding | 129.00 | 0 |
| 7 | Sugar 2kg | Staples | 38.00 | 25 |
| 8 | Matches | Load shedding | 6.50 | 60 |
| ProductID | ProdName | Category | Price | Stock |
|---|---|---|---|---|
INSERT INTO tblProduct (ProdName, Category, Price, Stock)
VALUES ("Paraffin 1L", "Load shedding", 21.50, 15);
UPDATE tblProduct
SET Price = Price + 2
WHERE Category = "Staples";
UPDATE tblProduct
SET Price = 20, Stock = 5
WHERE ProductID = 2;
DELETE FROM tblProduct
WHERE Stock = 0;The table has 8 rows. How many rows does each statement change or remove, and what does the table look like afterwards?
UPDATE tblProduct SET Price = 10; DELETE FROM tblProduct;
Write the SQL for each change to tblLearner (LearnerID is an AutoNumber).
(a) Add a learner: Surname Mahlangu, Name Bongani, Grade 10, Sport Soccer, Cell 0791230000, born 12 February 2009, Mark 66.
(b) Petersen's mark should be 62, not 60: correct it.
(c) Remove every Grade 12 learner whose mark is below 50. How many learners does it remove from the table in Unit 2?
qryLearner.Close;
qryLearner.SQL.Text := 'SELECT Surname, Mark FROM tblLearner WHERE Grade = 12 ORDER BY Mark DESC';
qryLearner.Open;
qryLearner.Close;
qryLearner.SQL.Clear;
qryLearner.SQL.Add('SELECT Surname, Mark');
qryLearner.SQL.Add('FROM tblLearner');
qryLearner.SQL.Add('WHERE Grade = 12');
qryLearner.SQL.Add('ORDER BY Mark DESC');
qryLearner.Open;| Statement | Gives records back? | Run it with |
|---|---|---|
| SELECT | yes | Open |
| INSERT, UPDATE, DELETE | no | ExecSQL |
qryLearner.Close; qryLearner.SQL.Text := 'UPDATE tblLearner SET Mark = 62 WHERE Surname = "Petersen"'; qryLearner.ExecSQL; memOut.Clear; qryLearner.First; while not qryLearner.Eof do begin memOut.Lines.Add(qryLearner['Surname'] + ': ' + IntToStr(qryLearner['Mark'])); qryLearner.Next; end;
// a number: no quotes round it
sSQL := 'SELECT Surname, Mark FROM tblLearner WHERE Grade = ' + edtGrade.Text;
// text: double quotes round it
sSQL := 'SELECT Surname, Mark FROM tblLearner WHERE Sport = "' + edtSport.Text + '"';
qryLearner.Close;
qryLearner.SQL.Text := sSQL;
qryLearner.Open;
// typed Rugby, the second string becomes: ... WHERE Sport = "Rugby"
qryLearner.Close;
qryLearner.SQL.Clear;
qryLearner.SQL.Add('SELECT Surname, Mark');
qryLearner.SQL.Add('FROM tblLearner');
qryLearner.SQL.Add('WHERE Grade = :pGrade'); // :pGrade is the parameter
qryLearner.Parameters.ParamByName('pGrade').Value := StrToInt(edtGrade.Text);
qryLearner.Open;Circle the method you use to run each statement.
| 1 | SELECT Surname FROM tblLearner | Open ExecSQL |
| 2 | INSERT INTO tblLearner (Surname) VALUES ("Zulu") | Open ExecSQL |
| 3 | UPDATE tblProduct SET Stock = 0 | Open ExecSQL |
| 4 | SELECT COUNT(*) AS Num FROM tblLearner | Open ExecSQL |
| 5 | DELETE FROM tblSale WHERE SaleID = 110 | Open ExecSQL |
| 6 | SELECT DISTINCT Sport FROM tblLearner | Open ExecSQL |
The user types Rugby in edtSport and 65 in edtMin. (a) Write the exact text that ends up in sSQL. (b) Write the rows the query returns (use the table in Unit 2).
sSport := edtSport.Text;
iMin := StrToInt(edtMin.Text);
sSQL := 'SELECT Surname, Mark ' +
'FROM tblLearner ' +
'WHERE Sport = "' + sSport + '" ' +
'AND Mark >= ' + IntToStr(iMin);This button should add 5 to the mark of every learner in the grade typed in edtGrade. Find three errors.
procedure TfrmMain.btnRaiseClick(Sender: TObject);
begin
qryLearner.SQL.Text := 'UPDATE tblLearner SET Mark = Mark + 5' +
'WHERE Grade = ' + edtGrade.Text;
qryLearner.Open;
end;edtGrade holds a grade. When btnShow is clicked, use a parameterised query on qryLearner (parameter pGrade) to list the learners of that grade, highest mark first, in memOut, each as Surname: Mark. Show the number of learners in lblCount (for example 4 learners).
A database that stores the same fact in many places breaks in three predictable ways. You will see the breaks happen on paper, learn the rule that stops them (referential integrity), and then repair a badly designed table by normalising it step by step. A normalisation question can be set in every exam.
| OrderNo | OrderDate | CustCell | CustName | ProductCode | ProductName | UnitPrice | Qty |
|---|---|---|---|---|---|---|---|
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube | B01 | Brown bread | 16.50 | 3 |
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube | C04 | Candles (6) | 24.00 | 2 |
| 1002 | 2026/10/01 | 0734445566 | Mr Fortuin | B01 | Brown bread | 16.50 | 1 |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube | M07 | Maize meal 5kg | 54.90 | 1 |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube | C04 | Candles (6) | 24.00 | 4 |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters | E02 | Eggs (dozen) | 49.50 | 2 |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters | M07 | Maize meal 5kg | 54.90 | 2 |
| Anomaly | What goes wrong | In Think First |
|---|---|---|
| Insertion | you cannot record one fact without recording another unrelated fact | a new product has no order yet |
| Deletion | deleting a row also destroys a fact that you wanted to keep | cancelling order 1004 erases Ms Peters and the Eggs |
| Modification (update) | one fact is changed in some rows but not in others, so the data contradicts itself | a new cell number is typed in 3 of Mrs Dube's 4 rows |
| A good database has… | which means |
|---|---|
| data integrity | data that is accurate, consistent and complete (referential integrity and validation protect it) |
| minimal redundancy | each fact stored once; a planned backup is not harmful redundancy |
| data security | access only for authorised users, with different rights for different users |
| data independence | a change to the structure does not break the programs that use it |
| ease of maintenance | it is easy to add, change and delete data without anomalies |
Circle the anomaly that each situation shows.
| 1 | A school cannot record a new subject until at least one learner has chosen it. | Insertion Deletion Modification |
| 2 | When the last learner who takes Latin leaves, the fact that the school offers Latin disappears. | Insertion Deletion Modification |
| 3 | A teacher's cell number is typed on 40 rows. It is corrected on 38 of them. | Insertion Deletion Modification |
| 4 | A taxi cannot be added to the table until it has taken its first trip. | Insertion Deletion Modification |
| 5 | Cancelling the only booking for a hall removes the hall's hire price from the table. | Insertion Deletion Modification |
tblProduct holds the ProductIDs 1 to 8. A clerk types five new sales. Decide whether each ProductID exists, and so whether the row would be refused by a database that enforces referential integrity.
| SaleID | ProductID | Qty | ProductID exists? | Accepted? |
|---|---|---|---|---|
| 111 | 3 | 2 | ||
| 112 | 9 | 1 | ||
| 113 | 7 | 5 | ||
| 114 | 12 | 3 | ||
| 115 | 1 | 1 |
In two or three sentences explain what referential integrity is, using tblSale and tblProduct, and what the database should do if someone tries to delete product 4 while sales of product 4 exist.
| Normal form | The table must… | If not, then… |
|---|---|---|
| 1NF | have one value per cell, no repeating groups of columns, and a primary key | split the lists into separate rows; choose a key (it may need two fields) |
| 2NF | be in 1NF and every non-key field must depend on the whole key (this only matters when the key has two or more fields) | move each field that depends on only part of the key into a new table, with that part as its key |
| 3NF | be in 2NF and no non-key field may depend on another non-key field | move the dependent fields into a new table whose key is the non-key field they depend on (which stays behind as a foreign key) |
| OrderNo | OrderDate | CustCell | CustName | Products ordered |
|---|---|---|---|---|
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube | B01 Brown bread R16.50 × 3 C04 Candles (6) R24.00 × 2 |
| 1002 | 2026/10/01 | 0734445566 | Mr Fortuin | B01 Brown bread R16.50 × 1 |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube | M07 Maize meal 5kg R54.90 × 1 C04 Candles (6) R24.00 × 4 |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters | E02 Eggs (dozen) R49.50 × 2 M07 Maize meal 5kg R54.90 × 2 |
| OrderNo | OrderDate | CustCell | CustName | ProductCode | ProductName | UnitPrice | Qty |
|---|---|---|---|---|---|---|---|
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube | B01 | Brown bread | 16.50 | 3 |
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube | C04 | Candles (6) | 24.00 | 2 |
| 1002 | 2026/10/01 | 0734445566 | Mr Fortuin | B01 | Brown bread | 16.50 | 1 |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube | M07 | Maize meal 5kg | 54.90 | 1 |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube | C04 | Candles (6) | 24.00 | 4 |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters | E02 | Eggs (dozen) | 49.50 | 2 |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters | M07 | Maize meal 5kg | 54.90 | 2 |
| OrderNo PK | OrderDate | CustCell | CustName |
|---|---|---|---|
| 1001 | 2026/10/01 | 0821112233 | Mrs Dube |
| 1002 | 2026/10/01 | 0734445566 | Mr Fortuin |
| 1003 | 2026/10/02 | 0821112233 | Mrs Dube |
| 1004 | 2026/10/03 | 0617778899 | Ms Peters |
| ProductCode PK | ProductName | UnitPrice |
|---|---|---|
| B01 | Brown bread | 16.50 |
| C04 | Candles (6) | 24.00 |
| M07 | Maize meal 5kg | 54.90 |
| E02 | Eggs (dozen) | 49.50 |
| OrderNo PK | ProductCode PK | Qty |
|---|---|---|
| 1001 | B01 | 3 |
| 1001 | C04 | 2 |
| 1002 | B01 | 1 |
| 1003 | M07 | 1 |
| 1003 | C04 | 4 |
| 1004 | E02 | 2 |
| 1004 | M07 | 2 |
| CustCell PK | CustName |
|---|---|
| 0821112233 | Mrs Dube |
| 0734445566 | Mr Fortuin |
| 0617778899 | Ms Peters |
| OrderNo PK | OrderDate | CustCell FK |
|---|---|---|
| 1001 | 2026/10/01 | 0821112233 |
| 1002 | 2026/10/01 | 0734445566 |
| 1003 | 2026/10/02 | 0821112233 |
| 1004 | 2026/10/03 | 0617778899 |
Learners book school camps. The primary key is CampCode and LearnerNo together.
| CampCode | LearnerNo | CampName | CampFee | Surname | DatePaid |
|---|---|---|---|---|---|
| C1 | 11 | Drakensberg | 950 | Nkosi | 2026/02/10 |
| C1 | 12 | Drakensberg | 950 | Pillay | 2026/02/12 |
| C2 | 11 | Cederberg | 600 | Nkosi | 2026/03/01 |
| C2 | 14 | Cederberg | 600 | Adams | 2026/03/05 |
| C3 | 12 | Robben Island | 350 | Pillay | 2026/03/10 |
Draw an ERD for the finished design of Mama Dube's shop: tblCustomer, tblOrder, tblOrderLine and tblProduct. Write the fields, mark the PKs and FKs, and write 1 and M at the correct ends of each line.
Theory questions in Paper 2 reward explanations, not word lists. In this unit you learn how data is collected, stored and mined, how it is looked after, and what a smartphone and Big Data mean for privacy and for society. Every answer is written as a short paragraph, and you learn why that matters.
Complete the table.
| When | What happened | Data collected and who uses it |
|---|---|---|
| 07:10 | The alarm app and the weather app open on your phone. | |
| 09:30 | You order a minibus-taxi seat through a ride app and the driver sees your location. | |
| 11:00 | You pay for airtime at the spaza shop with your bank card. | |
| 13:00 | At the supermarket you scan your loyalty card at the till. | |
| 15:30 | You search for trainers on a website, then see adverts for trainers on every other site. | |
| 18:00 | You stream a series and the app suggests the next one. |
| Method | How it works | Example |
|---|---|---|
| Forms (paper or web) | a person types or ticks the data in | registration form, online survey |
| RFID tags | a chip answers a reader's radio signal, so items are logged without contact or typing | library books, e-toll tag, access card |
| Cookies | a small file that a website saves on your device to remember you and track what you browse | a shopping cart, targeted adverts |
| Transaction records | every sale is saved with date, time, place and amount | card payments, till slips |
| Loyalty cards | the card links every purchase to one named customer over many years | a supermarket card |
| Sensors and apps | devices measure and send data (location, movement) all the time | a ride app, a fitness band |
A supermarket gives out loyalty cards. In a paragraph, explain how the card collects data about a customer and how the supermarket can use that data.
Differentiate between a database and a data warehouse in a short paragraph. Give both sides in each sentence.
A clerk types a learner's mark of 98 as 89. Explain the difference between validation and verification using this example, and say which of them could catch the mistake.
A learner installs a free torch app that asks for permission to use her location, contacts and microphone. In a paragraph, explain two privacy risks to the learner. Then explain one risk to a company whose employee uses a phone for work.
Discuss one benefit and one danger of mining Big Data for society. Write a paragraph.
No notes, no computer. Show all your working. Write Delphi code neatly and use correct indentation.
A taxi association keeps these tables. The primary key of tblRank is RankID, and RankID is a foreign key in tblTrip. Question: write a query that shows the TripID, Fare and Passengers of the trips with 10 or more passengers, with the highest fare first.
| RankID PK | RankName | Manager |
|---|---|---|
| 1 | Bellville | Mr Fortuin |
| 2 | Parow | Mrs Jansen |
| 3 | Goodwood | Mr Mthembu |
| 4 | Elsies River | Ms Daniels |
| TripID PK | RankID | Fare | TripDate | Passengers |
|---|---|---|---|---|
| 201 | 1 | 28.00 | 2026/10/01 | 14 |
| 202 | 2 | 22.50 | 2026/10/01 | 9 |
| 203 | 1 | 31.00 | 2026/10/02 | 15 |
| 204 | 3 | 19.00 | 2026/10/02 | 6 |
| 205 | 2 | 24.00 | 2026/10/03 | 12 |
| 206 | 1 | 27.00 | 2026/10/04 | 11 |
| 207 | 3 | 21.00 | 2026/10/04 | 8 |
| 208 | 2 | 26.00 | 2026/10/05 | 13 |
| 209 | 1 | 30.00 | 2026/10/05 | 10 |
| 210 | 3 | 18.00 | 2026/10/06 | 5 |
Show the TripID, RankID and TripDate of the trips from ranks 1 and 3 that took place on or after 3 October 2026. Use IN for the ranks.
For the trips of rank 2, show the TripID and a calculated column called Income (Fare multiplied by Passengers).
Write one query that gives the number of trips (NumTrips), the total number of passengers (TotalPax) and the highest fare (MaxFare).
Work out the result of this query on the tables above.
SELECT RankID, COUNT(*) AS NumTrips, ROUND(AVG(Fare), 2) AS AvgFare FROM tblTrip GROUP BY RankID HAVING AVG(Fare) > 20;
| RankID | NumTrips | AvgFare |
|---|---|---|
Write a query that shows the RankName, TripDate and Fare of every trip with a fare above R25, in order of date. Join the tables with WHERE.
Show each RankName and the money its trips earned (Fare × Passengers added up, called Takings), the biggest amount first.
Write the SQL for each of these three changes.
(a) Add a trip for rank 4: fare R25.50, 7 October 2026, 7 passengers (TripID is an AutoNumber).
(b) Add R2 to the fare of every trip of rank 3.
(c) Delete every trip with fewer than 6 passengers.
Circle the method that runs each statement.
| 1 | SELECT TripID FROM tblTrip WHERE RankID = :pRank | Open ExecSQL |
| 2 | DELETE FROM tblTrip WHERE TripID = 210 | Open ExecSQL |
| 3 | UPDATE tblTrip SET Fare = Fare + 2 | Open ExecSQL |
The user types 2 in edtRank. (a) Write the exact text stored in sSQL. (b) Write the TripID and Fare of the rows returned (use the tables in question A1).
sRank := edtRank.Text;
sSQL := 'SELECT TripID, Fare ' +
'FROM tblTrip ' +
'WHERE RankID = ' + sRank + ' ' +
'AND Fare >= 24 ' +
'ORDER BY Fare';edtMinFare holds a fare. When btnShow is clicked, use a query with one parameter (pFare) to list in memTrips the TripID and fare of every trip whose fare is above that fare, highest fare first, each line as TripID: Rfare. Show the number of trips in lblNum.
A teacher stores learner subjects like this:
| LearnerNo | Surname | Subjects |
|---|---|---|
| 31 | Zulu | IT, Maths, English |
| 32 | Pillay | Maths, Science |
A school keeps the results of its athletics day in one table. The primary key is LearnerNo and EventCode together.
| LearnerNo | Surname | HouseCode | HouseHead | EventCode | EventName | Result |
|---|---|---|---|---|---|---|
| 21 | Zulu | GRE | Mr Daniels | E1 | 100 m | 13.2 s |
| 21 | Zulu | GRE | Mr Daniels | E3 | Long jump | 4.85 m |
| 22 | Moodley | RED | Ms Pretorius | E1 | 100 m | 12.8 s |
| 23 | Smit | GRE | Mr Daniels | E2 | 800 m | 2:41 |
| 23 | Smit | GRE | Mr Daniels | E3 | Long jump | 4.10 m |
| 24 | Sibiya | RED | Ms Pretorius | E2 | 800 m | 2:35 |
A supermarket gives its customers a loyalty card. In a paragraph, explain two ways in which the shop collects data about a customer and how it can mine that data.
Differentiate between a database and a data warehouse.
Explain the difference between validation and verification, with an example of each.
A delivery rider's smartphone drains its battery by lunchtime and becomes hot when he uses the map. (a) Explain two hardware reasons why this happens. (b) Give one privacy risk of the rider's phone to the delivery company.