AQA 8525 GCSE Computer Science · 3.7 Relational Databases and SQL

Stretch tasks Relational Databases and SQL

Task 1

Quiz Challenge

A quiz game against four computer players, then short and long written answers.

  1. Quiz Blitz12 questions against the clock
  2. Quick Fire4 short answers
  3. Big Think2 long answers

About 20 minutes

Task 2

This or That

Pixel the cat asks 8 questions. Each has two answers: pick the right one.

  • Two answers to every question
  • A fish treat for every right answer
  • Streaks win Pixel shades, then a party hat

About 4 minutes

Task 3

Memory Match

Flip the cards two at a time to match each term card to its meaning card.

  • 12 cards: each term has a meaning
  • One peek at every card
  • Combo points for pairs found in a row

6 pairs, about 4 minutes

Task 4

Sort It

Sort each statement into the right box, like the tick-box tables in the exam.

  • 12 cards to sort into 4 boxes
  • Drag a card, tap a box or press its number
  • Combo points for cards sorted in a row

12 cards, about 4 minutes

The games need JavaScript. Every question is below, with the answers at the end.

Read the lesson: Relational Databases and SQL

Relational Databases and SQL: the questions

Quiz Challenge, round 1: Quiz Blitz

  1. In a database table, what is a record?

    • One row, describing one instance
    • One column, holding one attribute
    • The whole table
    • A link between two tables
  2. What is a primary key?

    • A field whose value is unique for every record
    • The first field in the table
    • A password for the database
    • A field that sorts the table
  3. What does a foreign key do?

    • Sorts the records
    • Names the database's owner
    • Holds another table's primary key, linking the tables
    • Encrypts the table
  4. Which TWO problems come from storing everything in one table?

    Tick 2.

    • Smaller files
    • Stronger encryption
    • Redundancy: the same data stored many times
    • Update anomalies: copies that disagree
    • Faster searches
  5. What does this query return?

    SELECT firstName, surname
    FROM Students
    WHERE yearGroup = 11
    ORDER BY surname ASC
    • Every field for every student
    • Year 11 students, sorted Z to A by surname
    • Only the surnames of Year 11 students
    • Year 11 students' first names and surnames, A to Z by surname
  6. Which keyword after ORDER BY sorts results in descending order?

  7. A primary key is always the first field in the table.

    • True
    • False
  8. Which condition is written correctly?

    • WHERE surname = Khan
    • WHERE 'surname' = Khan
    • WHERE surname 'Khan'
    • WHERE surname = 'Khan'
  9. What does % mean in WHERE title LIKE '%computing%'?

    • Percentage
    • Exactly one digit
    • The end of the table
    • Any sequence of characters
  10. Which statement changes values already stored in a table?

    • UPDATE
    • INSERT
    • SELECT
    • DROP
  11. Why does a join need a condition such as WHERE Borrowers.borrowerID = Loans.borrowerID?

    • Without it, every borrower is paired with every loan
    • It encrypts the data
    • SQL cannot open two tables otherwise
    • It deletes duplicate records
  12. What is the name for one column of a table, holding one attribute of every record?

Quiz Challenge, round 2: Quick Fire

  1. Write an SQL query to list the title and price of every book in the Books table that costs less than 10, cheapest first. [3 marks]

  2. Explain why a library should store borrowers in a separate table from loans, rather than repeating each borrower's address on every loan. [2 marks]

  3. Explain the difference between a primary key and a foreign key. [2 marks]

  4. This statement was meant to move only the Year 10 students into Year 11. Explain what it actually does, and how to fix it. [2 marks]

    UPDATE Students
    SET yearGroup = 11

Quiz Challenge, round 3: Big Think

  1. A cinema stores films and screenings in one table: every screening row repeats the film's title, certificate and running time. Explain the problems this causes, and describe how the data should be structured instead, using keys. [6 marks]

  2. A school database has a Students table (studentID, firstName, surname, yearGroup) and a Clubs table (clubID, studentID, clubName). Write SQL to: list the surname of every student in the chess club, alphabetically; add a new student 5120, Ola Bello, in Year 9; and delete club record 77. [6 marks]

This or That: tick the right answer

  1. Is a record a row or a column?

    • A column
    • A row
  2. Can two records share the same primary key value?

    • Yes, if their names differ
    • No: each value is unique
  3. Text in a WHERE condition: quotation marks or not?

    • No quotation marks: Khan
    • Quotation marks: 'Khan'
  4. Which keyword filters the records returned?

    • SELECT
    • WHERE
  5. Which links a Loans table to a Borrowers table?

    • A wildcard
    • A foreign key
  6. Which statement adds a new record?

    • INSERT INTO
    • UPDATE
  7. What does DELETE FROM Books do, with no WHERE clause?

    • Deletes only the first record
    • Deletes every record
  8. You want books whose title contains 'cat' anywhere. Which condition?

    • title = 'cat'
    • title LIKE '%cat%'

Memory Match: match each term to its meaning

TermMeaning
A Record1 One column, holding one attribute
B Field2 The same data stored more than once
C Primary key3 % in LIKE: any characters
D Foreign key4 One row of a table
E Redundancy5 Uniquely identifies each record
F Wildcard6 Holds another table's primary key

Sort It: tick one box in each row

Which part of an SQL query does each job or fragment belong to?

StatementSELECTFROMWHEREORDER BY
Sorts the results
surname DESC
Borrowers.borrowerID = Loans.borrowerID
ASC for A to Z
* for every field
Borrowers, Loans when joining two tables
Filters which records are returned
Names the table or tables
Lists the fields to show
mark >= 70 AND yearGroup = 11
firstName, surname
title LIKE '%computing%'
Answers

Round 1: Quiz Blitz

  1. One row, describing one instance A record is a row. A field is a column.
  2. A field whose value is unique for every record It identifies each record. It need not be the first field.
  3. Holds another table's primary key, linking the tables The foreign key is how a loan points back to exactly one borrower.
  4. Redundancy: the same data stored many times; Update anomalies: copies that disagree Splitting the data into linked tables stores each fact once.
  5. Year 11 students' first names and surnames, A to Z by surname SELECT the fields, FROM the table, WHERE the records match, ORDER BY to sort.
  6. desc ASC is ascending, DESC is descending.
  7. False It is the field whose value is unique for every record, wherever it sits.
  8. WHERE surname = 'Khan' Text values need quotation marks. Numbers do not.
  9. Any sequence of characters The wildcard lets LIKE match part of a value.
  10. UPDATE UPDATE ... SET ... WHERE changes existing records.
  11. Without it, every borrower is paired with every loan Matching the primary key to the foreign key performs the join.
  12. field Fields are columns. Records are rows.

Round 2: Quick Fire

    • SELECT title, price
    • FROM Books WHERE price < 10
    • ORDER BY price ASC
    Model answer
    SQL
    SELECT title, price
    FROM Books
    WHERE price < 10
    ORDER BY price ASC
    • Each address is stored only once, removing redundancy
    • Changing an address is one edit, so copies cannot disagree
    Model answer

    Each borrower's address is then stored only once, which removes redundancy and saves space. When a borrower moves, it is one edit, so the database can never hold two contradictory addresses.

    • A primary key uniquely identifies each record in its table
    • A foreign key holds the primary key of another table, linking them
    Model answer

    A primary key is a field whose value is unique for every record, so it identifies each record in its table. A foreign key is a field holding the primary key of a record in another table, which links the two tables.

    • It changes every student, because there is no WHERE clause
    • Add WHERE yearGroup = 10
    Model answer

    It sets every student in the table to Year 11, because there is no WHERE clause. Adding WHERE yearGroup = 10 limits the change to the Year 10 students.

Round 3: Big Think

    • Redundancy: each film's details are stored many times, wasting space
    • Update anomalies: a change means editing each copy
    • Copies can disagree, leaving inconsistent data
    • A film with no screenings cannot be recorded
    • Split the data into separate tables
    • The films table has a primary key such as filmID
    • The screenings table holds filmID as a foreign key
    • Each film's details are then stored once, so a change is one edit
    Model answer

    Storing it all in one table causes redundancy: each film's details are stored many times, wasting space. It also causes update anomalies: if a running time changes, each copy must be edited, and if one is missed the data becomes inconsistent, with two contradictory values. A film with no screenings yet cannot be recorded at all, which is an insertion problem. Instead, the data should be split into two tables. A Films table holds each film's details once, with filmID as its primary key, and a Screenings table holds filmID as a foreign key, linking each screening to exactly one film. A change is then one edit in one place.

    • SELECT surname
    • FROM Students, Clubs
    • WHERE Students.studentID = Clubs.studentID
    • AND clubName = 'Chess'
    • ORDER BY surname
    • INSERT INTO Students
    • VALUES (5120, 'Ola', 'Bello', 9)
    • DELETE FROM Clubs WHERE clubID = 77
    Model answer
    SQL
    SELECT Students.surname
    FROM Students, Clubs
    WHERE Students.studentID = Clubs.studentID
    AND Clubs.clubName = 'Chess'
    ORDER BY Students.surname ASC
    
    INSERT INTO Students(studentID, firstName, surname, yearGroup)
    VALUES (5120, 'Ola', 'Bello', 9)
    
    DELETE FROM Clubs
    WHERE clubID = 77

This or That

  1. A row A record is one row. A field is one column.
  2. No: each value is unique A primary key identifies one record, so no two records may share a value.
  3. Quotation marks: 'Khan' Text values need quotation marks. Numbers, such as 11, do not.
  4. WHERE SELECT picks the fields. WHERE picks the records.
  5. A foreign key Each loan holds the borrower's ID, which is the primary key of the Borrowers table.
  6. INSERT INTO UPDATE changes values already stored. INSERT INTO adds a new record.
  7. Deletes every record Without WHERE, the statement applies to every record in the table.
  8. title LIKE '%cat%' = needs an exact match. LIKE with the % wildcard matches part of a value.

Memory Match

  • A 4 Record: One row of a table
  • B 1 Field: One column, holding one attribute
  • C 5 Primary key: Uniquely identifies each record
  • D 6 Foreign key: Holds another table's primary key
  • E 2 Redundancy: The same data stored more than once
  • F 3 Wildcard: % in LIKE: any characters

Sort It

  1. ORDER BY Sorts the results ORDER BY sorts.
  2. ORDER BY surname DESC DESC sorts Z to A, after ORDER BY.
  3. WHERE Borrowers.borrowerID = Loans.borrowerID Matching the keys is a condition in WHERE, and it performs the join.
  4. ORDER BY ASC for A to Z ASC means ascending order.
  5. SELECT * for every field SELECT * returns every field.
  6. FROM Borrowers, Loans when joining two tables Both tables are named after FROM.
  7. WHERE Filters which records are returned WHERE picks the records.
  8. FROM Names the table or tables FROM says where the data is.
  9. SELECT Lists the fields to show SELECT names the fields you want.
  10. WHERE mark >= 70 AND yearGroup = 11 Conditions joined with AND belong in WHERE.
  11. SELECT firstName, surname A list of fields follows SELECT.
  12. WHERE title LIKE '%computing%' A LIKE condition filters records, so it is WHERE.