Skip to content
SPM Tuition
Data and databases practice

Data and databases: mixed practice

You have read the database lessons and want to see whether they hold on new questions.

These eight original questions cover entities, keys, diagrams and simple SQL. Try each before opening the answer.

This set belongs to data and databases. A teacher can review your working in the one-hour trial class (from RM50), a taught lesson on the Computer Science topic you choose.

Questions

Question 1. In a scenario about a gym, sort these: Member, membership fee, joins, Trainer. Give the type of each.

Answer

Member and Trainer are entities. Membership fee is an attribute, probably of Member. Joins is a relationship, linking Member to the gym or a class.

Question 2. A Student table has StudentID, Name and Class. Which column is the best primary key and why?

Answer

StudentID. It is unique, never empty and stable. Name can repeat, and Class changes when a student moves.

Question 3. The Loan table has LoanID, MemberID and BookID. Which columns are foreign keys?

Answer

MemberID and BookID. Each holds the primary key value of a row in the Member and Book tables. LoanID is the primary key of Loan.

Question 4. State the relationship: one school house has many students, and each student belongs to one house.

Answer

One-to-many, from House to Student. The foreign key HouseID sits in the Student table.

Question 5. A diagram shows STUDENT (M) attends (M) SUBJECT. What must you add to store this in tables?

Answer

An intermediate table, for example Enrolment, holding StudentID and SubjectID. A many-to-many relationship cannot be stored with a single foreign key.

Question 6. Use the table Item (ItemName, Price, Category) with rows (Teh Tarik, 2.50, Drink), (Nasi Lemak, 4.00, Food), (Milo, 3.00, Drink). What does SELECT ItemName FROM Item WHERE Price > 2.50; return?

Answer

Price above 2.50 passes for Nasi Lemak (4.00) and Milo (3.00). Teh Tarik is exactly 2.50, which is not greater than 2.50. The output is Nasi Lemak and Milo.

Question 7. Write a query for the same table that shows all drinks, cheapest first.

Answer
SELECT ItemName, Price
FROM Item
WHERE Category = 'Drink'
ORDER BY Price;

The result lists Teh Tarik (2.50), then Milo (3.00).

Question 8. A student wrote WHERE Category = Drink. What is wrong?

Answer

Text values need quotation marks, so it should be Category = 'Drink'. Without quotation marks, the system reads Drink as a column name.

If you got these wrong

For question 1, review entities, attributes and relationships. For questions 2 and 3, read choosing primary and foreign keys.

For questions 4 and 5, use reading an entity relationship diagram. For questions 6 to 8, see writing simple SQL queries.

To go deeper, try relational data modelling. For a teacher’s help, see online one-to-one Computer Science tuition.

Common questions

How should I attempt this set?

Try every question without notes, then open the answers one at a time. Write each wrong answer in a short list with the reason. Retry the wrong ones after two or three days.

What if I cannot picture the tables?

Draw them. Sketch each table as a small grid with two or three sample rows. Seeing the rows makes foreign keys and query outputs far easier to work out.

Do the SQL questions match my school's syntax?

They use the standard SELECT form. If your school uses slightly different syntax, follow your teacher's version. The logic of filtering and sorting is the same.

If the same kind of database question keeps going wrong, a one-to-one Computer Science teacher can work through your attempts and find the pattern behind the errors.

  • 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.