大象传媒

Testing and evaluationFinding errors

A database is fit for purpose if it meets the end use and functional requirements. Testing queries and examining actual output against expected output helps to determine fitness for purpose.

Part of Computing ScienceDatabase design and development

Finding errors

In the example on the previous page, the predicted result and actual result do not match.

When this happens, it is necessary to go back to the design and implementation phases to try to identify the error.

Design

Query Design: Return a list of all pupils grouped by their pastoral care teacher and ordered by their merits points in descending order

Field(s)First Name, Surname, Pastoral Care Teacher, Merit Points
Table(s)Pupil
CriteriaGROUP BY Pastoral Care Teacher
Sort OrderMerit Points DESC
Field(s)
First Name, Surname, Pastoral Care Teacher, Merit Points
Table(s)
Pupil
Criteria
GROUP BY Pastoral Care Teacher
Sort Order
Merit Points DESC

The design for the query is fine.

Implementation

A mistake has been made during implementation.

SELECT firstname, surname, pastoralCareTeacher, meritPoints
FROM Pupil
ORDER BY meritPoints DESC
GROUP BY pastoralCareTeacher;

The reason our actual result is not the same as our predicted result is because GROUP BY must precede ORDER BY. If we swapped the order of these SQL clauses, then the query should work as intended.

The SQL code should have read:

SELECT firstname, surname, pastoralCareTeacher, meritPoints
FROM Pupil
GROUP BY pastoralCareTeacher;
ORDER BY meritPoints DESC

This would return:

PupilIDFirst NameSurnameClassPastoral Care TeacherMerit Points
0010ThomasGlacney1M1Miss Armstrong91
0011FrankieAl-Robeye1M2Mr Gilchrist71
0003AmyJones1M1Mr Gilchrist55
0006AntoniaGallagher1M2Mr Gilchrist21
0004JamesMcNamee1T1Mr Harley88
0009BeatricePanner1T2Mr Harley77
0001ZainabSingh1T1Mr Harley74
0007AmyMcNamee1T1Mr Harley63
0008AyshaMatazinadze1T1Mr Harley45
0005PawelMcTavish1I1Mrs Aitken19
0002DavidBoland1I2Mrs Aitken12
PupilID0010
First NameThomas
SurnameGlacney
Class1M1
Pastoral Care TeacherMiss Armstrong
Merit Points91
PupilID0011
First NameFrankie
SurnameAl-Robeye
Class1M2
Pastoral Care TeacherMr Gilchrist
Merit Points71
PupilID0003
First NameAmy
SurnameJones
Class1M1
Pastoral Care TeacherMr Gilchrist
Merit Points55
PupilID0006
First NameAntonia
SurnameGallagher
Class1M2
Pastoral Care TeacherMr Gilchrist
Merit Points21
PupilID0004
First NameJames
SurnameMcNamee
Class1T1
Pastoral Care TeacherMr Harley
Merit Points88
PupilID0009
First NameBeatrice
SurnamePanner
Class1T2
Pastoral Care TeacherMr Harley
Merit Points77
PupilID0001
First NameZainab
SurnameSingh
Class1T1
Pastoral Care TeacherMr Harley
Merit Points74
PupilID0007
First NameAmy
SurnameMcNamee
Class1T1
Pastoral Care TeacherMr Harley
Merit Points63
PupilID0008
First NameAysha
SurnameMatazinadze
Class1T1
Pastoral Care TeacherMr Harley
Merit Points45
PupilID0005
First NamePawel
SurnameMcTavish
Class1I1
Pastoral Care TeacherMrs Aitken
Merit Points19
PupilID0002
First NameDavid
SurnameBoland
Class1I2
Pastoral Care TeacherMrs Aitken
Merit Points12

Now that the actual result matches the predicted result, testing is complete for this query.