EXAM QUESTIONS · IGCSE 0478

Databases and SQL Exam-Style Questions with Answers (IGCSE 0478)

Original exam-style questions on databases and SQL for Cambridge IGCSE Computer Science 0478 (Paper 2): records and fields, primary keys, data types, validation, and SQL with SELECT, FROM, WHERE, ORDER BY, AND, OR, COUNT and SUM. There are 25 marks in total. Query outputs mark themselves – then press Show answer for the mark scheme.

Use this table for all the questions. A bookshop stores data about its books in a database table called BOOKS.

BookIDTitleAuthorGenreYearPriceStock
B101The Silent OrbitK MendesSci-Fi20159.994
B102Dragons of AshL OkaforFantasy19987.500
B103Code BreakersP HaleHistory200912.002
B104Moonfall CityK MendesSci-Fi19946.257
B105The Glass CrownA RivaFantasy20218.753
B106Robots at DawnS TanakaSci-Fi20185.990
Question 1[2 marks]
  1. State the number of records in the table. [1]
  2. State the number of fields in the table. [1]
Show answer
  1. 6 [1]
  2. 7 [1]
Question 2[2 marks]

Identify the field that should be the primary key and explain why.

Show answer
  • BookID [1]
  • Each book has a different BookID, so it uniquely identifies every record. (Other fields, such as Author or Genre, can repeat.) [1]
Question 3[3 marks]

State the most suitable data type for each field.

  1. Title [1]
  2. Price [1]
  3. Stock [1]
Show answer
  1. Text / alphanumeric [1]
  2. Real [1]
  3. Integer [1]
Question 4[4 marks]

Write an SQL query to output the Title and Author of all books in the Fantasy genre, in alphabetical order of Title.

Show answer
SELECT Title, Author
FROM BOOKS
WHERE Genre = 'Fantasy'
ORDER BY Title ASC;
  • 1 mark: SELECT Title, Author
  • 1 mark: FROM BOOKS
  • 1 mark: WHERE Genre = ‘Fantasy’
  • 1 mark: ORDER BY Title (ASC is optional)

Output: Dragons of Ash, L Okafor · The Glass Crown, A Riva

Question 5[2 marks]

State the output of this query:

SELECT Title
FROM BOOKS
WHERE Price < 8 AND Stock > 0;
Show answer

Moonfall City [2]

Dragons of Ash and Robots at Dawn cost less than 8 but have Stock 0, so they are not output. 1 mark for Moonfall City, 1 mark for no other titles.

Question 6[3 marks]
  1. Write an SQL query to count how many books were published before the year 2000. [2]
  2. State the result of your query. [1]
Show answer
  1. SELECT COUNT(*)
    FROM BOOKS
    WHERE Year < 2000;
    1 mark: SELECT COUNT(*) FROM BOOKS, 1 mark: WHERE Year < 2000 [2]
  2. 2 (Dragons of Ash 1998, Moonfall City 1994) [1]
Question 7[3 marks]
  1. Write an SQL query to find the total number of Sci-Fi books in stock. [2]
  2. State the result. [1]
Show answer
  1. SELECT SUM(Stock)
    FROM BOOKS
    WHERE Genre = 'Sci-Fi';
    1 mark: SELECT SUM(Stock) FROM BOOKS, 1 mark: WHERE Genre = ‘Sci-Fi’ [2]
  2. 11 (4 + 7 + 0) [1]
Question 8[2 marks]

State the output of this query, in the correct order:

SELECT BookID
FROM BOOKS
WHERE Author = 'K Mendes' OR Stock = 0
ORDER BY Year DESC;
Show answer

B106, B101, B102, B104 [2]

The matching books are B101 (2015), B102 (1998), B104 (1994) and B106 (2018). DESC sorts them from the newest year to the oldest. 1 mark for the correct four BookIDs, 1 mark for the correct order.

Question 9[2 marks]

Describe a validation check that could be used on the Price field.

Show answer
  • Range check [1]
  • to make sure the price is greater than 0 (e.g. between 0.01 and 100). [1]

A type check (must be a real number) or a presence check, with a suitable description, is also accepted.

Question 10[2 marks]

A new book is added with the same BookID as an existing book. Explain why this would cause a problem.

Show answer
  • BookID is the primary key, so every value must be unique. [1]
  • Two records with the same BookID could not be told apart, so the wrong book could be found, changed or deleted (the database would reject the duplicate). [1]

Frequently asked questions

Which SQL commands do I need for IGCSE Computer Science 0478?

SELECT, FROM, WHERE, ORDER BY (with ASC or DESC), AND, OR, SUM and COUNT, used on a single table.

What is a primary key?

A field that uniquely identifies each record in a table, so no two records can have the same value.

Can I practise SQL online?

Yes. Our free SQL practice playground lets you run real SQL queries and checks your answers.

Revise the topic: IGCSE databases notes · SQL practice playground · Common SQL mistakes · All exam-style questions