Previous exam paper: 2019 Nov
QUESTION 2: SQL AND DATABASE
The hockey organiser at your school requires your assistance with the administration of the
players, teams and coaches.
The database HockeyDB contains two tables called tblPlayers and tblTeams.
The data pages attached at the end of this question paper provide information on the
design of the database and the content of the tables.
Do the following:
Open the incomplete project file called Question2_P.dpr in the Question 2 folder.
Enter your examination number as a comment in the first line of the Question2_U.pas
unit file.
Compile and execute the program. The program has no functionality currently.
The content of the tables is displayed as shown below on the selection of Tabsheet
Question 2.2 - Delphi code.
Follow the instructions below to complete the code for EACH section, as described in
QUESTION 2.1 and QUESTION 2.2 that follow.
Use SQL statements to answer QUESTION 2.1 and Delphi code to answer QUESTION
2.2.
QUESTION 2_1 | Marking Grid | 1
NOTE:
The 'Restore database' button is provided to restore the data contained in the
database to the original content.
The content of the database is password protected, in other words you will not be able to
gain access to the content of the database using Microsoft Access.
Code is provided to link the GUI components to the database. Do NOT change any of the
code provided.
TWO variables are declared as global variables, as described in the table below.
Variable Data type Description
tblTeams TADOTable Refers to the table tblTeams in the database
HockeyDB
tblPlayers TADOTable Refers to the table tblPlayers in the database
HockeyDB
2.1 Tab sheet [Question 2.1 - SQL]
Example of the GUI for QUESTION 2.1:
NOTE:
Use ONLY SQL statements to answer QUESTION 2.1.1 to UESTION 2.1.5.
Code is provided to execute the SQL statements and display the results of the
queries. The SQL statements assigned to the variables sSQL1, sSQL2,
sSQL3, sSQL4 and sSQL5 are incomplete.
Complete the SQL statements to perform the tasks described in QUESTION
2.1.1 to QUESTION 2.1.5 that follow.
2.1.1 Button [Best players]
Display the surnames and names of all players with a skills level of 10.
Example of output of the first four records:
(3)
QUESTION 2_1 | Marking Grid | 2
2.1.2 Button [B-team coaches]
Display the names o f the coaches and teams of all the B-teams.
Example of output:
(4)
2.1.3 Button [Percentage games won]
Code has been provided to extract a team name from the combo box,
cmbQ2_1_3.
Display the name of the team, their coach and the percentage of games won by
the team. Save the percentage of games won in a calculated field called
PercentageGamesWon.
Example of output if the u/14 B team was selected:
NOTE: You do NOT have to format the calculated value. (4)
2.1.4 Button [Team average more than 6]
The average skills levels of teams are used to identify teams with the highest
possibility of winning their games.
Display the names and average skills levels of all teams with an average skills level
of more than 6. The average skills level per team must be saved in a calculated
field called AverageSkillsLevel, formatted to ONE decimal place.
Example of output:
(5)
2.1.5 Button [Update games won]
The results of the games won during the last sports day must be used to
update the NumberOfGamesWon field. Only the u/14 B team lost their game.
Update the data in the tblTeams table by adding a value of 1 to the
NumberOfGamesWon field for the teams who won their game.
Example of output:
QUESTION 2_1 | Marking Grid | 3
(3)
2.2 Tab sheet [Question 2.2 - Delphi code]
Example of GUI for QUESTION 2.2
NOTE:
Use ONLY Delphi programming code to answer QUESTION 2.2.1 and QUESTION 2.2.2.
NO marks will be awarded for SQL statements in QUESTION 2.2.
2.2.1 Button [Junior players in u/18 A team]
The u/18 A team includes some of the junior players that are
exceptionally talented. Junior players are players that were born after the
year 2002.
NOTE: The first two digits of the IDNumber field indicate the year of birth
of a player.
Write code to do the following:
Save the surnames and names of all the junior players who are members of the
u/18 A team to a new text file called Junior18A.txt.
Determine the total number of junior players in the u/18 A team and display the
result in the lblQ2_2_1 label.
Example of content of the Junior18A text file:
Example of output to be displayed on the lblQ2_2_1 label:
(11)
QUESTION 2_1 | Marking Grid | 4
2.2.2 Button [Coach and goalkeeper information]
The coach and goalkeeper of all the teams are invited to a special
training session.
Code has been provided to set the various column widths and to display
the headings, as shown in the example of output.
Write code to display a list containing the following information on each team:
Name of the team
Surname and initials of the coach
Surname and name of the goalkeeper in the format:
<Surname>, <Name>
Example of output of the first five records:
(10)
Enter your name as a comment in the first line of the program file.
Save your program.
TOTAL: 40
QUESTION 2_1 | Marking Grid | 5
DATABASE INFORMATION OF HockeyDB FOR QUESTION 2:
The design of the database tables is as follows:
Table: tblTeams
This table contains the data of all the hockey coaches.
Field name Data type Description
TeamName (PK) Text (10) A unique team name. A team name is saved in
the format 'u/18 A', where A indicates an
A-team, B indicates a B-team and so on. The
number 18 is the age group of the team players.
Coach Text (25) The surname and initials of the team's coach
NumberOfGamesPlayed Integer The total number of games the team played this
season
NumberOfGamesWon Integer The total number of games the team won this
season
Example of the first four records of the tblTeams table:
Table: tblPlayers
This table contains the data of the hockey players of three different age groups:
Field name Data type Description
PlayerID (PK) Autonumber A unique number assigned to the player
PlayerSurname Text (25) The surname of the player
PlayerName Text (25) The name of the player
IDNumber Text (20) The South African ID number – first 6 digits is the
person's date of birth in the format yymmdd.
TeamName Text (10) The team name that the player is a member of, e.g.
'u/18 A'
SkillsLevel Integer A value in the range 1 to 10 indicating the player's skills
level. A value of 1 indicates a low skills level. A value of
10 indicates a high skills level.
GoalKeeper Boolean A value indicating whether the player is a goalkeeper
(true) or not (false)
QUESTION 2_1 | Marking Grid | 6
Example of the first four records of the tblPlayers table:
NOTE:
Connection code has been provided.
The database is password protected, therefore you will not be able to access the
database directly.
The following one-to-many relationship with referential integrity exists between the two tables
in the database:
QUESTION 2_1 | Marking Grid | 7