Chapter 18 Databases
Chapter 18 Databases
Databases
GETTING STARTED
Here are two lists. One contains terms relating to databases and the other their definitions or explanations.
Unfortunately, they are not in the same order. Working with a partner, try to work out which number from
the first list goes with which letter from the second.
370
18 Databases
CONTINUED
Discussion questions
1 How many databases hold information about you? Discuss this in your group and make a list of as many
as you can.
2 One of the organisations holding information about you is your school or college. Make a list of all of
the items of information that are stored about you.
371
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
372
18 Databases
To convert his flat-file database into a relational The obvious choice is the Pupil Number. This can be
database the teacher could create two linked tables: one given when the pupil enters the school or college and
showing the personal details of the students and the can be unique for each pupil. No other pupil can ever
other showing their academic results. have the same Pupil Number. A field that holds unique
information is a key field and, as the Pupil Number field
Pupil table is going to be used to identify each record, it is called the
primary key.
Pupil Number Surname First Name
1036 Suparmanputra Hasan Therefore, in order to link the two tables together, Pupil
Number, the key field in the Pupil table, can be added
2872 Elmasry Anat to the Academic table to provide the link. This field will
1725 Nasution Abdul identify the students who the results belong to.
3916 Megat Amina The Academic table will now look like Table 18.5.
7321 Nababan Annisa
1328 Mansour Hasina Academic table
1712 Zaky Khalid Pupil Subject Course- Examination Total
Number work
2482 Sakura Abe
1036 Science 60 70 130
2223 Mazur Lucia 2872 History 56 82 138
3669 Sayid Haziq 1725 Geography 90 80 170
Table 18.3: Personal details of the students 3916 Computing 82 69 151
7321 Computing 73 67 140
1328 Science 42 39 84
Academic table
1712 Maths 76 85 161
Subject Coursework Examination Total 2482 Science 39 52 91
Science 60 70 130 2223 Languages 68 54 122
History 56 82 138 3669 Technology 32 76 108
Geography 90 80 170 Table 18.5: Academic details of the students with a primary
Computing 82 69 151 key (the Pupil Number)
Computing 73 67 140
Science 42 39 84 Now each subject is linked to a specific pupil through
their Pupil Number, which is in both tables (see
Maths 76 85 161 Table 18.6 on the next page). When a primary key is
Science 39 52 91 added to another table to link them together, it is called a
Languages 68 54 122 foreign key. In the Academic table, the foreign key, Pupil
Number, refers to the primary key in the Pupil table. You
Technology 32 76 108
can have a primary key without a foreign key but you
Table 18.4: Academic details of the students
KEY WORDS
However, there is now a serious problem. How do you
link the two tables together? How do you know which unique: something of which there is only
subject goes with each student? one example
In the Pupil table you can chose a field that contains key field: a field that holds unique information
unique data to identify individual pupils.
primary key: the key field used to identify
You cannot use the Surnames or First names as there each record
may be several people with the same names. Some
students may even have both names the same. foreign key: a field in one table that refers to a
primary key in another table
373
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
374
18 Databases
KEY WORDS
field name: also called a label or column
heading, is the name for a column by which it can
be identified. E.g. Name, Date Modified, Type,
Size, etc.
data type: the different types of data that each
field can hold, such as date/time, text, etc.
integer: a whole number with no decimal places
Figure 18.3: Selecting a table in Design View There are many different data types, described in
Table 18.9.
It should be saved with a new name; in this database, it Further properties of the data type can be set in the area
is named Pupil (see Figure 18.4). below. In this case the number is being set as a ‘long
The fields can now be designed. The field name and data integer’ (see Figure 18.6). An integer is a whole number
type have to be defined (see Figure 18.5). with no decimal places. An integer can store numbers
from −32 768 to +32 767 whereas a long integer from
−2 147 483 648 to +2 147 483 647.
375
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Long integer
376
18 Databases
You can access the different options by clicking on the short date (see Figure 18.9 on the next page). Try each
drop-down arrow on the right of the Field Properties and see what the difference is.
box (see Figure 18.7).
For the House field, the text length can be set to 6
The First Name field can be created and formatted in characters, as the longest entry will be ‘Yellow’. As there
the same way. are only four correct entries for this field, a validation
rule can be created to ensure that only one of those four
The Date of Birth field should be set as a Date/
is entered (see Figure 18.10 on the next page).
Time field and the way in which the date is
displayed can be set as long date, medium date and
Field size
377
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
378
18 Databases
The validation rule ‘Like `Red´ Or `Blue´ Or `Green´ Or else. Be aware that validation rules are case sensitive and
`Yellow´’ will ensure that only one of those options can so ‘red’ would not be allowed; the database would only
be entered, and the validation text ‘This is not one of accept ‘Red’.
the four houses.’ will inform a user if they enter anything
Boolean field
379
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
The Transport field has only two correct entries: ‘Yes’ and A new table can be created by selecting Table Design in
‘No’. As these can also be interpreted as ‘True’ and ‘False’, the Create ribbon (see Figure 18.14). The fields are set
this is called a Boolean data field (see Figure 18.11 on the up in the same way as for the Pupil table.
previous page).
The table is going to be saved before the Total field is
When the data is being entered into the table, this field is added, but first the primary key has to be selected. This
usually shown as a checkbox. is going to be a compound key of the Pupil Number and
the Subject fields.
Finally, the Pupil Number field has to be selected as the
key field. This can be done by right-clicking the grey box The boxes next to each other should be selected by
to the left of the file name and selecting ‘Primary Key’ holding down Shift and clicking on the grey boxes next
(see Figure 18.12 on the previous page). to the file name. Key Field should be chosen after
right-clicking (see Figure 18.15 on the next page).
The table should now be saved and opened in normal
view for data entry. You can reopen the table by double- When selecting fields to form a compound key, they
clicking its icon in the left-hand pane (in Figure 18.13, must be next to each other. Fields can be easily dragged
you would double-click on Pupil, which is highlighted to different positions in the table by clicking on the grey
in pink). box next to the file name and dragging it to where you
want that field to be.
Academic table The reason that the table has been saved before the
In a similar way, a table can be created for the Total field is added is that this field is going to do a
Academic data. calculation by adding the data in the Coursework and
Examination fields. This is called a calculated field.
Table 18.10 shows the names of the fields. Before the table is saved, the field names cannot be used
in a calculation.
Pupil Subject Course- Examination Total
Number work
KEY WORD
Table 18.10: Fields for database
calculated field: a field whose data is calculated
from other fields
380
18 Databases
Key fields
381
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Practice
3 Open the Students database into your database software.
4 All of the tests are marked out of 100.
Open the Maths table in design view and apply suitable validation rules to the following fields:
• FirstTermTest
• SecondTermTest
• ThirdTermTest.
Also provide suitable validation text to warn the user if the rules are broken.
Take screenshots of the fields in design view to show the rules and paste them into a document
named Task1.doc.
Take a screenshot of the error message when incorrect data is entered and paste it into Task1.doc.
5 Use Save As to save the database as Student1 into your personal area with the changes that
you have made.
Challenge
6 Create a validation rule for the ‘Gender’ field with suitable validation text.
7 Format the ‘Gender’ field to ensure that the data is always in upper case.
8 Create a validation rule for the ‘DateOfBirth’ field. All students in this group should be born between
2005 and 2007.
9 Take screenshots of these fields showing the rules and paste them into Task1.doc. Save the file as
Task1_Challenge.doc. Save the database as Student1_Challenge.
382
18 Databases
Practice
3 In the database you saved in Practical Task 18.1 (Student1_Challenge), open the Maths table in design
view and create a new field named ‘Average’.
4 Make this a calculated field with an expression to find the average of the three test results.
5 Format this field as integer.
6 Save the table and open it to see the new field.
7 Manually check the results in three records to ensure that it is working as expected.
Take screenshots of the field in design view to show the calculation. Paste it into a document named
Task2.doc.
8 Use Save As to save the database with the name Student2 into your personal area on the computer
with the changes that you have made.
Challenge
9 Change the format of the ‘Average’ field so that it shows the calculation with one decimal place.
Take screenshots of the field in design view to show the specification and paste it into Task2.doc.
10 Sort the records so that they are in alphabetical order according to surname.
Take a screenshot of the result and paste it into Task2.doc. Save the file as Task2_Challenge.doc.
Save the database as Student2_Challenge.
383
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
ACTIVITY 18.2
Carry out research and find out information on
two other types of relationships between tables.
Create a poster explaining the differences
between them.
This dialogue box displays the fields from the two tables, In a CSV file, the data for the different fields are
and at the bottom, shows that it is a ‘one-to-many’ separated by a comma (see Figure 18.21). In ordinary
relationship. This means that in the Pupil table, the Pupil text files they are usually separated by a tab
Number of an individual pupil can appear only once (see Figure 18.22).
but in the Academic table it can appear many times,
depending on the number of subjects studied by a pupil. KEY WORDS
If the ‘Enforce Referential Integrity’ box is checked, then
one-to-many relationship: where the data in one
the RDMS will ensure that there are no ‘orphans’ left
row of a table can be linked to data in many rows
behind (i.e. if a pupil is deleted from the Pupil table,
of another table
having the box ticked will ensure that there are no
records for that student in the Academic table). referential integrity: preventing orphan
When Create is clicked, the tables will be shown with records – records that reference records in other
their relationship (see Figure 18.20). tables that no longer exist
orphan: records that reference records in other
tables that no longer exist
comma separated value (CSV): this file
format can be used on data saved in a
table structured format, such as a spreadsheet
or a database, where each value is separated
by a comma
384
18 Databases
1 Select New Data Source from the External Data Ribbon 2 The file to be used and the table to import the data
and then Text File into are selected
3 The information to be imported is shown 4 The comma is used as a separator and the first row
that contains the Field names can be confirmed
5 The import table is confirmed 6 Confirmation that the data has been imported
Figure 18.23: Steps for importing a CSV file
385
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
386
18 Databases
387
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Copy the tables onto a piece of paper and draw lines showing the fields that link the tables together.
2 What is the type of relationship between tblMembers and tblMember_Sport?
388
18 Databases
CONTINUED
Practice
The table in the Students.accdb database that you saved after Practical Task 18.2 (Student2 or
Student2_Challenge) contains data about the students and their Maths results.
There is another csv file that contains data about the students and their IT results (ITResults.csv).
This needs to be imported into the database.
3 Instead of creating a completely new table, copy the Maths table and paste it back into the
database as a table named IT. You can do this by right-clicking on the Maths table icon in the left
pane to copy and again to paste.
4 Delete all of the records in this table and import ITResults.csv into it.
There are now two tables in the database, Maths and IT.
Unfortunately, the data in these two tables breaks one of the major rules of database design.
There is a lot of duplication of data. The student numbers, first names, surnames, genders and
dates of birth are duplicated – they are in both tables. Very bad!
But it can be solved.
5 Copy one of the two tables and paste it into the database as Students.
• Delete all of the fields containing termly results and the average from the student table so
that only the student data remains.
• Delete the FirstName, Surname, Gender and Date of Birth fields from the Maths and IT tables.
DO NOT delete the StudentNumber fields as they are needed to link the three tables.
6 In your database program set up the relationships between these three tables.
Take a screenshot of the relationships, like the one on in the Getting started questions, and
paste it into a document named Task3.doc.
7 Save the database as Student3.
Data from the three tables can be combined by using a query. Manipulating data using queries
is covered later in this chapter.
8 As a very difficult challenge look at the section on manipulating data and create a query using
the three tables. The following fields should be included in the query:
• SecondName
• FirstName
• Average from the Maths table
• Average from the IT table.
Run the query and take a screenshot. Paste it into document Task3.doc and save it as
Task3_Challenge.doc.
9 Save the database as Student3_Challenge.
389
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Form Wizard
390
18 Databases
391
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
•
Characteristics of good Simplicity – instead of entering your gender
as male or female, use a drop-down box or
form design radio buttons.
The characteristics of good form design should include: • Attractiveness – well-designed forms are usually
attractive. Attractive forms encourage users to fill
• Effectiveness – the form should work as it them out. This is because it appears easier than a
was intended. poorly designed form that might have too much or
• Accuracy – the data entry form should use database too little white space.
tools that would ensure that accurate data is more • Consistency – consistency in shapes and colours
likely to be entered by using drop-down lists. Users help to create a consistent layout of the form.
could simply choose from a list, rather than type
their own responses in and risk making spelling • Intuitive navigation – it should be easy to move
mistakes or using incorrect words that would affect from one item to other related ones without having
data output. to search for them.
Check boxes
In the design view of our Students database, a
check box can be set to represent the Transport field
so that a tick indicates if transport is needed (see
Figure 18.37).
This is done by adding it to the form and then linking
it to the Transport field (see Figure 18.38 on the
next page).
392
18 Databases
Figure 18.40: The combo box wizard Figure 18.41: Entering the list options
393
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Where to
save the value
can be selected from a drop-down menu or combo box Figure 18.43: Selecting an item from the combo box
(see Figure 18.39 on the previous page).
After selecting the Combo Box icon on the design
ribbon (see Figure 18.39), a combo box can be drawn on
the form. The Combo Box Wizard will then open asking
where the items for the box are located. They could be in
another table; but for the Pupil form, they will be typed
in (see Figures 18.40–41 on the previous page).
Finally, the combo box is instructed to save the selected Figure 18.44: Example of radio buttons
option in the House field (see Figure 18.42).
Options can be chosen from the drop-down menu Normally only the radio buttons would be shown.
(see Figure 18.43). It is shown here to confirm that selecting ‘Red’ will
cause 1 to be entered into the field.
394
18 Databases
2 Select one as a default value or have no default. 3 Assign values to the options. In this case 1, 2, 3 and 4.
4 Select the field to store the value. 5 Select the option buttons and their style.
Figure 18.46: Steps for creating an option group
395
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
396
18 Databases
Aspects and items that are useful when creating well- Design features Functions
designed data entry forms include those shown in
Table 18.11. Check boxes Check boxes allow users to
make choices from a list of
options. It helps users to make
ICT IN CONTEXT decisions quickly by simply
selecting those on a pre-made
To protect their citizens, most countries have
list instead of asking users to
enacted laws to ensure the people who hold
compile their own lists. They
the data do not misuse it and store it securely
reduce the possibility of input
(data protection acts). The European Union
errors in a database. Check
strengthened the laws in member countries in
boxes allow the user to select
2018 to make them the strictest in the world. You
multiple answers.
can look at United Nations websites to see the
countries where citizens are protected and those Drop-down Drop-down menus make it
where there is no legislation. menus even easier for users to select
from options that are already
there to choose from. They
reduce the possibility of input
Design features Functions errors in a database. They allow
Use of white Data entry forms with too much only one choice.
space white space between fields or Appropriate font Attractive data entry forms
with answer boxes that are too styles and sizes encourage users to fill in data
large look unattractive but if they might otherwise have
they are too cramped they may taken longer to give you.
be difficult to follow. Using appropriate font styles
Radio buttons Radio buttons allow users to and sizes can help to create
make a choice from several attractive data entry forms.
options simply by clicking Character spacing Aligning characters to the
on it. They reduce the of individual fields centre, left or right within
possibility of input errors in a individual fields can make
database. These allow for only a data entry form easier on
one choice. the human eye to process
data quicker.
Table 18.11: Design features for creating forms
Practice
3 Open the Student3 or Student3_Challenge database that you saved in Practical Task 18.3.
4 Create a data entry form for the Students table.
397
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
5 Create a suitable heading and colour scheme. Arrange the fields so that data is easy to edit
and enter, and the form is not cluttered.
6 On the form remove the scroll bars and record navigation bar.
7 Create command buttons for:
• Go to first record
• Go to previous record
• Go to next record
• Go to last record
• Create a new record
• Delete a record.
An example is shown in Figure 18.53.
Take a screenshot of your form and paste
it into a document named Task4.doc.
8 Save the database as Students_Task4. Figure 18.53: Example Student data entry form
Challenge
9 So that users do not have to scroll through all
the records to find a particular student, create
a combo box control on the form based on
the Students table.
This should allow the user to select a particular
student from a list and their record will be
shown on the form.
An example is shown in Figure 18.54.
Take a screenshot of your form with the list
selected and paste it into Task4.doc.
398
18 Databases
CONTINUED
10 At the moment the combo box control is
based on the table and the students are not
shown in alphabetical order.
Change the data source for the control so
that the students are in alphabetical order
(see example in Figure 18.55).
Take a screenshot of your form with the list
selected and paste it into Task4.doc. Save the
document as Task4_Challege.doc.
Save the database as Student4_Challenge.
Figure 18.55: Select control with students in alphabetical order
Operator Example
18.2 Manipulating data AND Both conditions must be true.
An advantage of storing data in an organised way is that
it can be searched to find specific information and sorted Subject must be Like Computing AND
in different ways. The data can also be analysed to find Total must be greater than 150 would
totals and averages of different fields. return only those students where both
conditions are true.
An AND query has the criteria written
Search and select data on the same line.
Searches to find specific data are also called OR Only one of the conditions must be true.
queries, which can be created using relational
database management software. When relationships Subject must be Like Computing OR
have been created, many tables can be used within Total must be greater than 150 would
each query. return all the students who study
Computing and all those whose Total is
Queries use logical operators (see Table 18.12) to
greater than 150, whatever the subject.
compare values in different fields.
When Query Design is selected from the Create ribbon, An OR query has the criteria written on
the tables to be used in the query have to be selected different lines.
NOT Subject NOT Computing would
return all the students who do not
KEY WORDS
study computing.
query: a method of interrogating the data held Table 18.12: Logical operators
in a database
logical operator: operator such as AND, OR, (see Figure 18.56). (Some programs have a selection
NOT, which perform comparisons values in pane appear rather than a dialogue box.)
different fields
The fields to be used in the query can be moved to the
criterion: an expression used to query field grid by dragging or double-clicking on the field names.
values. Criteria is the plural form of criterion The search criterion is written in the ‘Criteria’ row
in one of the field columns. In Figure 18.57, the
399
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
400
18 Databases
The sorting could also have been set up in design view Field: Name Subject Total Mark
(see Figure 18.65 on the following pages).
Sort: Ascending Descending
Sorting can be carried out on more than one field in
Criteria:
each search. The example in Table 18.13 would show
each student alphabetically and then each of their or:
subjects according to Total Mark, sorted highest Table 18.13: Sorting two fields
to lowest.
401
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
402
18 Databases
403
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Sorting criteria
404
18 Databases
Search operators Usually LIKE and NOT are used for text fields and =
and <> are used for number fields.
When searching the operators shown in Table 18.14 can
be used. (Note: the examples given only show positive The operators AND and OR have been explained in the
numbers; answers can also include negative numbers.) examples above.
405
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Question
4 Describe what the following criteria are intended to find and how the results will be displayed.
Field: Name Performer Position In Charts Genre Length in Minutes Year Released
Sort: Ascending
Criteria: <=10
or:
Field: Name Performer Position In Charts Genre Length in Minutes Year Released
Sort: Descending
Criteria: >2019
or:
Field: Name Performer Position In Charts Genre Length in Minutes Year Released
Sort: Ascending
Criteria: <=40 Rock
or:
Field: Name Performer Position In Charts Genre Length in Minutes Year Released
Sort: Ascending
Criteria: 2017
or: 2018
Field: Name Performer Position In Charts Genre Length in Minutes Year Released
Sort: Ascending Ascending
Criteria: *lonely*
or:
406
18 Databases
KEY WORDS
Run-time calculations formula: arithmetical operations carried out
Calculations and analyses can be programmed to on the contents of cells. The plural of formula
occur when a query is run. These are called run-time is formulae
calculations and use formulae and built-in functions.
Formulae, using arithmetic operators such as +, −, * function: a block of reusable code that can be
and / can be applied to the data returned in a search to used to perform an action
produce a new column with calculated information.
arithmetic operator: symbols to represent
The following would have a column named ‘Difference’ arithmetic operations such as addition,
showing the difference between the Coursework mark subtraction, multiplication and division
and the Examination result. The field names have to be
in square brackets […], so you would type in:
Division and multiplication can also be used. The example
Difference: [Coursework]-[Examination] in Figure 18.68 (on the next page) shows the ratio between
(Don’t forget the colon!) the coursework and examination by dividing the former
407
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
by the latter. The field has been set to two decimal places Built-in functions such as those shown in Table 18.16
by using the field properties. can be used at run time. They are used in conjunction
with using the Totals icon.
Figure 18.69 shows the results of the ratio calculation.
408
18 Databases
Function Explanation
Sum Will add the data to find the total
Average Will find the average or mean of a set of numbers
Maximum Will find the maximum number of a set of numbers
Minimum Will find the minimum number of a set of numbers
Count Will count the number of items.
Table 18.16: Built-in functions
In the Academic table, the subjects studied by each This adds a new row to the query grid (see Figure 18.71).
student and their coursework, examination and total It shows that the data will be grouped by the Surname
marks are shown for each of their subjects. An analysis field and that the average Total field for the number of
that teachers often need is to find details of these results subjects they study will be found. All of the subjects will
without showing each of them. They may want to know not be shown, just the average of their totals.
how many subjects a student has studied, which was
When the query is run it will show the average of each
their best or worst result and the average. These can be
student’s total marks (see Figure 18.72).
found by using the functions in Table 18.16.
The Total field can be added more times to the grid
When the fields have been added to the query grid, the
and functions for Sum, Min, Max and Count can be
Totals icon is selected from the Design ribbon
specified (see Figure 18.73).
(see Figure 18.70). This icon has nothing to do with the
‘Total’ field and can be used whatever the field name. Figure 18.74 now shows the results when the query is run.
409
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Totals icon
Totals row
410
18 Databases
411
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Practice
3 Open SampleDatabase.accdb into your database software. It contains a table listing assets
(equipment) bought by the different departments of a company over the last year.
Familiarise yourself with the field names and the data the fields contain.
4 Create a query to show all items with a warranty of at least 12 months.
The query should contain the fields Asset Category, Cost and Warranty.
The results should be sorted by length of warranty, with the largest first
Save the query as qry_Warranty.
Take screenshots of the query in design view and when it is run, and paste them into a document
named Task5.docx.
5 Create a query to show all items listed as Computer Hardware in the Asset category and costing
from $2000 to $3000 dollars inclusive.
Save the query as qry_2 to 3 thousand.
Take screenshots of the query in design view and when it is run, and paste them into Task5.docx.
6 Create a query to find all of the assets listed as Computer Hardware and costing over $1000.
Display the fields Asset Category, Description and Cost.
The results should be sorted by Description in alphabetical order and then by Cost in
descending order.
Save the query as qry_ComputerHardware over $1000.
Take screenshots of the query in design view and when it is run, and paste them into Task5.docx.
412
18 Databases
CONTINUED
7 Create a query to show all of the five different Owners in one column with the sum of their costs
over the year.
Save the query as qry_Owners.
Take screenshots of the query in design view and when it is run, and paste them into Task5.docx.
8 Save your database as Student5.
Challenge
9 There are many instances of Office Furniture in the Asset category, and in the description there are
six different descriptions of Office Furniture.
Create a query to show the six Office Furniture descriptions with a Count of the number of
times they appear.
Save the query as qry_OfficeFurniture.
Take screenshots of the query in design view and, when it is run, paste them into a document
named Task5_Challenge.docx.
10 Create a query to find which Owners ordered Computer Hardware and the number of times
they ordered them.
Save the query as qry_ComputerHardware By Owner.
Take screenshots of the query in design view and, when it is run, paste them into the document
named Task5_Challenge.docx.
Save the database as Student5_Challenge.
18.3 Presenting data Report footer Appears only once at the end of the
data on the last page of the report.
Data is stored and manipulated in a database in order Page header Appears at the top of each page of
to provide information. This information should be the report.
displayed in as user friendly a way as possible so that
people can easily see and understand the results. Page footer Appears at the bottom of each
page of the report.
Relational database management software provides the
facilities to present information in reports which can be Table 18.17: Parts of a database report
413
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Every report must have data provided by a table or Both page headers and footers and report headers and
a query. These can be attached to the report as it is footers can be removed, and added, by right-clicking on
being created. the report and selecting from the menu (see Figure 18.77
on the next page).
A report can be created in design view by selecting
Report Design from the Create ribbon (see Figure 18.75). A table or query has to be attached to the report to
supply the data to be displayed. In this example, we will
Page header and footer sections are already created
add a query linking the Pupil table with the Academic
and information can be entered and edited (see
table. This can be done by selecting data from the
Figure 18.76).
Property Sheet.
414
18 Databases
The Property Sheet can be accessed by selecting it from Headings and titles can be added to a report by creating
the Design ribbon (see Figure 18.78). labels. The Label icon can be selected from the Design
ribbon (see Figure 18.80 on the next page).
The data can then be selected (see Figure 18.79).
Choose Report
Query selected
415
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Label icon
Property sheet
416
18 Databases
A label box can be drawn, and text can be entered. The fields can be dragged onto the report. In addition
The text can be formatted with respect to font, to each field, a label with the field name is provided
size colour, etc. by selecting it and changing (see Figure 18.83). They can be moved independently,
the properties of the label in the Property Sheet and the label can be deleted. Fields and labels can be
(see Figure 18.81 on the previous page). dragged into the Detail section of the report from the
Add Existing Field pane on the right-hand side.
The fields can be added to the report by selecting the
Add Existing Fields icon from the Design ribbon
(see Figure 18.82).
Add Existing Fields icon
Figure 18.83: A field and label in the report. The field has a yellow border
417
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
When the report is run, the students are shown but the
report shows each of the students with their first subject,
then each of the students with their second and third
subjects (see Figure 18.84).
418
18 Databases
ACTIVITY 18.5
At North East College, there are end-of-year
examinations in all subjects.
1 On paper, design a report that would display
the results for each student showing the
subjects studied and results.
2 On paper, design a report suitable for a
teacher showing the results for all subjects in
a particular teaching group.
419
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
420
18 Databases
The formulae and functions can be entered into the If the report needed to show the averages of the
text boxes. coursework and examination marks, then the following
could be entered in text boxes:
For example, if you wanted to count the number of
subjects for each pupil, the following function could be =Avg([Coursework])
entered into a text box:
=Avg([Examination])
=Count([Subject])
=Avg([Total])
Notice that the field name is in square brackets.
A text box can be used to show page numbers in the
page footer. It can combine both text and functions.
='Page ' & [Page] & ' of ' & [Pages]
These text boxes can be given a label (see Figure 18.91).
How a number will be displayed in a text box can be
set using the Property Sheet. In Figures 18.92–93,
the number is set as fixed with one decimal place, but
currency and percentage can also be set here.
By default, numbers are right-aligned in text boxes;
if the format is set to fixed, the decimal points will
be aligned. When creating a report, it is essential
to carefully ensure that all of the text and numbers
are aligned correctly so it is easy to understand (see
Figure 18.94).
The alignment of any label or control can be set using
the Property Sheet (see Figure 18.95).
To make the report easier to read, a line can be drawn
Figure 18.92: Formatting a text box
in the Surname Footer by selecting the line tool
(see Figure 18.96).
421
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
422
18 Databases
Output layouts
The report layout shown in the images in this chapter is
tabular. This means it shows the data in columns. The
other main layout is called a stacked layout and shows
the data as they would appear on a form, with each item
labelled (see Figures 18.100–101).
b d f
a c e
Figure 18.102: Form and report design tools
2 On paper, design a report that would show the students and their average marks for IT and Maths.
423
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
Practice
Open your Students database Student4 or Student4_Challenge from the Practical Task 18.4 and create a
report in design view to show the students and their average marks for IT and Maths. The report should
be grouped by Year of birth and then by gender.
3 First of all, create a query for the report.
It should include the Students, Maths and IT tables.
Use the following fields: StudentNumber, SecondName, FirstName, DateOfBirth, Gender, Average
from Maths table and Average from IT table.
A further field needs to be created named ‘Yr’ to contain the year element from the DateOfBirth
field by using an expression.
The data should be sorted by SecondName in ascending order.
Save this query as QueryReport.
4 Then, in design view, create a new report based
on this query.
The report should have the following
specifications.
• A width of 20 cm.
• A page header with the title ‘Analysis
report’, font size 24 pt, black, bold
and centred.
• It should be grouped on the ‘Yr’ field and
then on the ‘gender’ Field.
• These field names should be in their group
headers in 20 pt and bold.
• The detail should contain the Secondname,
FirstName, Maths average and IT Average.
• The last two fields should have labels
above them.
• Save the report as ‘Analysis Report’.
• Take a screenshot of the report in Print
Preview view and paste it into a document
named Task6.doc.
An example is shown in Figure 18.103.
Figure 18.103: Example analysis report
Save the database as Students6.
424
18 Databases
CONTINUED
Challenge
5 In the page footer, in the centre, place the date.
6 In the page footer at the right place the page
number in the following form:
[Page number] of [total number of pages],
for example, Page 1 of 3.
Take a screenshot of the report in Print Preview
view and paste it into Task6.doc.
An example is shown in Figure 18.104.
Save the database as Task6_Challenge.
Peer assessment
Print out and swap the reports with a partner. Assess each other’s reports by checking things such as:
• Headings are shown and are consistent.
• All labels and fields are lined up correctly.
• No text overflows from any of the controls.
• Date is shown in the page footer.
• Page number is shown in the page footer.
425
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
Step 1
The csv file (see Figure 18.105) contains details about students and their results for their termly tests saved
in csv format .
426
18 Databases
CONTINUED
Step 2
A new database file should be created (see Figure 18.106), and a new table designed for the data.
The file should be named and saved in a suitable location.
427
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
The StudentNumber field should be selected as the primary key (see Figure 18.108) as all of the
other fields could have non-unique information – for example, there may be two students with the
same name, date of birth or test scores.
The data can now be selected and imported into the table.
428
18 Databases
CONTINUED
The file name to be imported has to be selected, and also the table into which it is to be imported or
appended to (see Figure 18.109).
After clicking ‘OK’, the data will be imported and the program will notify if there any errors, such
as incorrect data types or text too long for a field.
The records can be viewed in the table (see Figure 18.110).
Step 3
The report can now be produced from this table.
The wizard can be used.
Select all of the fields.
429
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
Select ‘Gender’ as the field to group on.
The data does not need to be sorted and this form can be left blank.
430
18 Databases
CONTINUED
The orientation should be set to ‘Landscape’ and the layout to ‘Stepped’ for this report.
431
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
This report was set for a ‘Stepped’ layout. The other two options, ‘Block’ (see Figure 18.116) and
‘Outline’ (see Figure 18.117), produce similar reports.
The layout is not very good. For example, the sizes of the Gender, FirstName and SecondName fields are
too large and the test field labels are too small.
These can be adjusted by viewing the form in ‘Design view’.
The sizes of the fields and their labels can be adjusted.
432
18 Databases
CONTINUED
The field sizes have been adjusted.
Questions
1 Create a database file and table in your own software and import the data from MathsResults.csv
2 Add the following student and data (see its placement in Figure 18.120).
433
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
CONTINUED
434
18 Databases
REFLECTION
In small groups, talk about what you each found difficult in this chapter, and come up with ideas to
help each other learn the material.
SUMMARY
EXAM-STYLE QUESTIONS
1 Mrs Jackson is opening a cattery to look after the animals when their owners
go on holiday. To store the details of her guests, she has created the database
table (shown below) to store details of her guests. Some of the data is shown.
435
CAMBRIDGE IGCSE™ ICT: COURSEBOOK
Make screen prints of the queries in design view and paste them into
Evidence.doc. [6]
e i Create a report named rpt_Sports with the following specification. [15]
• It should be based on qry_Report.
• The report should have a width of 13 cm.
• It should have a page header of ‘Sports’ in a black, bold font
of 28 pt and should be centred.
436
18 Databases
CONTINUED
• The report should be grouped first by sport and then by
gender with suitable headings.
• The Surname and FirstName should be shown for each
member in the list.
• The footer for the sport should show the number of members
doing it and a horizontal line to separate it from the next sport.
• The page footer should show the text ‘Page’ followed by the
page number.
ii Take a screen print of the report in design view and paste it
into Evidence.doc. [1]
iii Take a screen print of a print preview of the first page your
report and paste it into Evidence.doc. [1]
[Total: 54]
SELF-EVALUATION CHECKLIST
After studying this chapter, think about how confident you are with the different topics.
This will help you to see any gaps in your knowledge and help you to learn more effectively.
You might find it helpful to rate how confident you are for each of these statements when you are revising.
You should revisit any sections that you rated ‘Needs more work’ or ‘Getting there’.
437