AQA 8525 GCSE Computer Science · 3.7 Relational Databases and SQL
Stretch tasks Relational Databases and SQL
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
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
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
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
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
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
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
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
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
Which keyword after ORDER BY sorts results in descending order?
A primary key is always the first field in the table.
- True
- False
Which condition is written correctly?
- WHERE surname = Khan
- WHERE 'surname' = Khan
- WHERE surname 'Khan'
- WHERE surname = 'Khan'
What does % mean in WHERE title LIKE '%computing%'?
- Percentage
- Exactly one digit
- The end of the table
- Any sequence of characters
Which statement changes values already stored in a table?
- UPDATE
- INSERT
- SELECT
- DROP
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
What is the name for one column of a table, holding one attribute of every record?
Quiz Challenge, round 2: Quick Fire
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]
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]
Explain the difference between a primary key and a foreign key. [2 marks]
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
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]
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
Is a record a row or a column?
- A column
- A row
Can two records share the same primary key value?
- Yes, if their names differ
- No: each value is unique
Text in a WHERE condition: quotation marks or not?
- No quotation marks: Khan
- Quotation marks: 'Khan'
Which keyword filters the records returned?
- SELECT
- WHERE
Which links a Loans table to a Borrowers table?
- A wildcard
- A foreign key
Which statement adds a new record?
- INSERT INTO
- UPDATE
What does DELETE FROM Books do, with no WHERE clause?
- Deletes only the first record
- Deletes every record
You want books whose title contains 'cat' anywhere. Which condition?
- title = 'cat'
- title LIKE '%cat%'
Memory Match: match each term to its meaning
| Term | Meaning |
|---|---|
| A Record | 1 One column, holding one attribute |
| B Field | 2 The same data stored more than once |
| C Primary key | 3 % in LIKE: any characters |
| D Foreign key | 4 One row of a table |
| E Redundancy | 5 Uniquely identifies each record |
| F Wildcard | 6 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?
| Statement | SELECT | FROM | WHERE | ORDER 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
- One row, describing one instance A record is a row. A field is a column.
- A field whose value is unique for every record It identifies each record. It need not be the first field.
- Holds another table's primary key, linking the tables The foreign key is how a loan points back to exactly one borrower.
- Redundancy: the same data stored many times; Update anomalies: copies that disagree Splitting the data into linked tables stores each fact once.
- 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.
- desc ASC is ascending, DESC is descending.
- False It is the field whose value is unique for every record, wherever it sits.
- WHERE surname = 'Khan' Text values need quotation marks. Numbers do not.
- Any sequence of characters The wildcard lets LIKE match part of a value.
- UPDATE UPDATE ... SET ... WHERE changes existing records.
- Without it, every borrower is paired with every loan Matching the primary key to the foreign key performs the join.
- field Fields are columns. Records are rows.
Round 2: Quick Fire
- SELECT title, price
- FROM Books WHERE price < 10
- ORDER BY price ASC
Model answerSQLSELECT 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 answerEach 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 answerA 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 answerIt 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 answerStoring 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 answerSQLSELECT 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
- A row A record is one row. A field is one column.
- No: each value is unique A primary key identifies one record, so no two records may share a value.
- Quotation marks: 'Khan' Text values need quotation marks. Numbers, such as 11, do not.
- WHERE SELECT picks the fields. WHERE picks the records.
- A foreign key Each loan holds the borrower's ID, which is the primary key of the Borrowers table.
- INSERT INTO UPDATE changes values already stored. INSERT INTO adds a new record.
- Deletes every record Without WHERE, the statement applies to every record in the table.
- 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
- ORDER BY Sorts the results ORDER BY sorts.
- ORDER BY
surname DESCDESC sorts Z to A, after ORDER BY. - WHERE
Borrowers.borrowerID = Loans.borrowerIDMatching the keys is a condition in WHERE, and it performs the join. - ORDER BY
ASCfor A to Z ASC means ascending order. - SELECT
*for every field SELECT * returns every field. - FROM
Borrowers, Loanswhen joining two tables Both tables are named after FROM. - WHERE Filters which records are returned WHERE picks the records.
- FROM Names the table or tables FROM says where the data is.
- SELECT Lists the fields to show SELECT names the fields you want.
- WHERE
mark >= 70 AND yearGroup = 11Conditions joined with AND belong in WHERE. - SELECT
firstName, surnameA list of fields follows SELECT. - WHERE
title LIKE '%computing%'A LIKE condition filters records, so it is WHERE.