Figure 8 shows part of the data a teacher holds on students and their test results, in the tables Student and TestResult.
Define the word relational database.
Our own questions on this topic, marked straight away, so you see what to revise. Free now.
Show model answer for 20.1Hide model answer for 20.1
A relational database is a database with more than one table, and the tables are linked together.
How the marks are earned
- A database that has more than one table.
- The tables are linked together. The word database in place of table earns nothing.
Why it scores
One mark for having more than one table and one mark for the tables being linked.
Revise SQLDefine the word foreign key.
See how you would score on SQLShow model answer for 20.2Hide model answer for 20.2
A foreign key is a field of one table whose values come from the primary key of a different table, and that is how the tables are linked.
How the marks are earned
- A field held in one table. Writing database where table is meant earns nothing.
- That field is the primary key of a different table. The reverse wording, a primary key whose values also appear as a field of another table, earns both marks.
Why it scores
One mark for the field being in one table and one mark for it being the primary key of another table.
Revise SQLState which field of the TestResult table in Figure 8 is its primary key.
See how you would score on SQLShow model answer for 20.3Hide model answer for 20.3
TestResultID. Each value is different, so it identifies one test result. StudentID cannot be the key because a student can appear in many results.
Write an SQL query on Figure 8 returning only first name, last name and Biology score for GCSE Year 1 students, highest score first.
See how you would score on SQLShow model answer for 20.4Hide model answer for 20.4
SELECT FirstName, LastName, Score
FROM Student, TestResult
WHERE Student.StudentID = TestResult.StudentID
AND GCSEYear = 1
AND Subject = 'Biology'
ORDER BY Score DESCSELECT FirstName, LastName, Score
FROM Student INNER JOIN TestResult
ON Student.StudentID = TestResult.StudentID
WHERE GCSEYear = 1 AND Subject = 'Biology'
ORDER BY Score DESCHow the marks are earned
- Mark A: the SELECT clause has only the three correct fields.
- Mark B: the FROM clause names one of the two tables correctly.
- Mark C: the second correct table in the FROM clause, or a correct INNER JOIN with ON. Writing INNERJOIN or just JOIN is accepted. The FROM clause must be fully correct.
- Mark D: the WHERE clause holds one correct condition.
- Mark E: all the correct conditions, joined correctly with AND. In the comma form this includes the StudentID match; in the INNER JOIN form that match is in ON and WHERE needs only the other two.
- Mark F: a correct ORDER BY clause, with no other ORDER BY.
- With any error in the code the maximum is 5 marks. A mistake of one kind repeated through the query costs one mark only: a swapped key word that still makes sense, a misspelt field name, stray characters such as colons, a field before a table, == for =, or wrong brackets. Table names before field names are fine when correct; single or double quotes round Biology are fine; quotes round 1, correctly formatted brackets round field and table names, case and small misspellings (not of SQL key words) are ignored.
Why it scores
SELECT picks the three fields. FROM names both tables, and the first condition in WHERE matches each result to its student. The other two conditions keep Year 1 students and Biology, and ORDER BY Score DESC puts the highest score first.
This is the same query written with a join. The ON part holds the matching condition, so both forms earn full marks.
Revise SQLMark's result T03 should read 28. Query: line 1 A TestResult; line 2 SET B; line 3 WHERE TestResultID = 'T03'. State A and B.
See how you would score on SQLShow model answer for 20.5Hide model answer for 20.5
A: UPDATE B: Score = 28
How the marks are earned
- A is UPDATE. Case and spacing are ignored; any spelling mistake earns nothing.
- B is Score = 28. Quotes round 28 are accepted; case and spacing are ignored; any spelling mistake earns nothing.
Why it scores
UPDATE changes records already in the table, and SET Score = 28 gives the new value, with WHERE limiting the change to test T03.
Revise SQL