Skip to content
SPM Tuition
Study problem · Computer Science

Telling a database question from a programming question

You read a question about records and cannot tell whether it wants a query or a program.

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.

Common questions

How do I know a question wants SQL and not a program?

Look for words such as table, record, field, key, query and display records where. Those point to a database question. Words such as variable, repeat, input, array and function point to programming. Some questions use both, so read the whole question first.

Is a SQL WHERE the same as an IF in a program?

They share the same logic. WHERE tests each row and keeps those that pass, like a loop with an IF inside it. The difference is the tool: SQL states what you want, and a program states how to get it, step by step.

Can one question ask for both?

Yes. A question might ask you to retrieve records with a query and then describe how a program would display them. Split the question into parts, name the tool for each part, and answer each in its own style.

What should I do if I cannot decide?

Underline the noun the question is about. If it is a stored table of records, think database. If it is a value that changes while steps repeat, think programming. Then write one line naming the tool before you start.

If you pick the wrong tool under time pressure, a one-to-one Computer Science teacher can give you mixed questions and ask you to justify the tool before you write anything.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.