A database question asks about stored records. A programming question asks for steps that change values as they run. The wording tells you which one you face.
This page helps when a question mixes the two, or when you start the wrong kind of answer and lose time.
What do the clue words tell you?
| Clue words in the question | Points to | Answer to write |
|---|---|---|
| table, record, field, key, relationship | Database | Table design or a query |
| retrieve, list records where, count records | Database | SELECT with WHERE |
| variable, input, repeat, array, function | Programming | Pseudocode or code |
| trace, output of the program | Programming | A trace table |
| display the result of a query in a page | Both | A query plus a short program |
Underline the clue words before you write anything. The habit takes ten seconds and prevents a whole wrong answer.
One task, two tools
Here is an original task. A fictional school has a list of club members with their ages: 14, 17, 15, 16 and 13. Count how many are at least 15.
As a database query. The data sits in a table called Member, with a field Age. The query is SELECT COUNT(*) FROM Member WHERE Age >= 15. SQL tests each row, and the rows with ages 17, 15 and 16 pass, so the answer is 3.
As a program. The same ages sit in an array. The steps are below.
count ← 0
FOR i ← 1 TO 5
IF age[i] >= 15 THEN
count ← count + 1
END IF
END FOR
OUTPUT count
Tracing gives count values of 0, 1, 2, 3, and the output is 3. The logic is the same: the test age >= 15 appears once in each language.
What is different about the two?
A query describes the result you want. You do not write a loop, because the database does the repeating.
A program describes how to reach the result. You control the variable, the loop and the stopping value. This is why programming questions ask you to trace, and database questions ask you to predict rows.
A common mistake
A student sees “count the members who are at least 15” and starts writing a FOR loop, although the question says the data is in a table and asks for a query. The logic is right, but the answer is in the wrong form and loses marks.
The fix is one sentence written first: “This is a query on the Member table.” The sentence commits you to a tool before you write.
How can you practise?
Take five past-style questions, cover the answer, and write only the tool name for each: query, program or both. Check against the clue words. Then solve one of them in each tool, as above.
The SQL reasoning sandbox helps with the query side, and the mistake log records which tool you confuse most. For the query skills, read writing simple SQL queries.
When is one-to-one tuition worth considering?
When you still choose the wrong tool after practising the clue words, a teacher can give mixed questions and ask you to justify each choice aloud. That exposes whether the confusion is wording or understanding.
You can try this in the one-hour trial class (from RM50), a taught lesson. See also online one-to-one Computer Science tuition.