Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
172 views55 pages

Cambridge IGCSE: Complete

Uploaded by

kadyrmurataliev0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views55 pages

Cambridge IGCSE: Complete

Uploaded by

kadyrmurataliev0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Cambridge IGCSE®

Complete
ICT
Third edition

Stephen Doyle
Mahmoud Farouk Bahnassy
Jimmy Arifin
Muhammad Naveed Rajput

Oxford excellence for Cambridge IGCSE®


18 Databases
When a large amount of data needs to be stored, it first needs to be
put into a structure by using spreadsheet or database software. Once The key concepts covered in this chapter are:
the data has been stored it can then be manipulated by performing  Creating a database structure
calculations, searches (i.e. queries), etc.  Manipulating data
 Presenting data

Creating a database structure


Data can be letters, symbols, numbers, images, sound. Together these Q UESTI O N S A
make up names, dates, exam results, photographs – as seen in your
school’s computer system where your information may be stored. 1 Data is to be stored in a structure and to do this a data
Database, spreadsheet and many other types of software require type must be chosen for each item of data.
that data is put into a structure. Once in this structure, it can be Choose a suitable data type from the following list for
manipulated and output in lots of different ways. An organised the data shown in the table: (6 marks)
store of data on a computer is called a database. Logical/Boolean
It is possible to create simple database structures using spreadsheet Text
or database software. There are two types of database called a flat- Numeric
file database and a relational database. Here, you will learn about the Date
important differences between the two types of data structure and
Name of field Example data Data type
also the way data is held more efficiently using a relational database.
Title (Mr, Mrs, Ms, Dr, etc.)
Data types Phone number 0798273232
Data entered into a computer for processing is usually one of the Sex M or F
following types:
Country Botswana
 Boolean/logical Date of birth 01/10/03
 Text Years at address 4
 Numeric (integer, decimal, percentage, currency)
 Date/time. 2 Here is a list of examples of data to be put into a
structure.
Boolean/logical Some of this data can have the logical/Boolean data
Boolean/logical data can have only one of two values: 1 or 0, yes type and some of it cannot.
or no, true or false, male or female, etc.
Complete the following table by placing a tick
Text in the box next to those items of data that could
Text refers to all the letters and numbers and other characters you use a logical/Boolean data type. (4 marks)
see on the keyboard that can be typed in.
Item of data Tick if data type is
Numeric (integer, decimal, percentage, currency) logical/Boolean
Decimal numbers are numbers containing numbers after the Driving licence (yes or no)
decimal point (e.g. 3.45) and integers are whole numbers Sex (M or F)
(i.e. positive, negative whole numbers and zero). Percentages Size (S, M, L, XL, XXL)
are numbers expressed as percentages and currency means
Airport code
numbers containing a currency symbol.
Car registration number
Date/time Date of purchase
There are lots of different ways of writing a date. The common Car type (manual or automatic)
ways include: Fuel type (diesel or petrol)
dd/mm/yy for example 12/03/21 for the date 12 March 2021
mm/dd/yy for example 03/12/21 for the date 12 March 2021

182 Times can also be included with the date.


18 DATABA SES

Database terms Each column represents


There are some database terms you will need to familiarise a field of the table.
yourself with. They are: Sex Year Tutor Group
Field: A field is a single item of data found in every record. M 7 Miss Hu
This row contains the
A field has a ‘Field Name’ to identify it in the database and M 7 Mr Zade set of the fields. Each
to help the user convert the text or number into meaningful F 8 Dr Hick row is a record.
information. An example would be Field Name: Surname, F 7 Mrs Wong
Data: Smith – means that we have information on a person M 7 Miss Kuyt
whose Surname is Smith. F 8 Mr Singh
Record: A record is a collection of fields – the data
held about one person, thing or place in a database. Field types
For example – your school record includes your name, address, There are many different data types; thus, when creating a
date of birth, exam results and the like – all the data about you. database structure, you must specify the field type based on the
A travel agent might have all the data about a hotel – name, type of data being entered. For example, a person’s name would
address, facilities, manager’s name, telephone number, room have the field type text.
types – this makes up the record for this hotel.
In commercial databases, you can have a placeholder for media
Table: In databases a table is used to store data with each that can be stored in a database. This media could be images
row in the table being a record and the whole table being a (e.g. a photograph of a student), sound bites (i.e. small sections
file. When only one table is used, it is a very simple database of sound), and video clips.
and it is called a flat-file database. For more complex
databases created using specialist database software, lots Primary key
of tables can be used and such a database is called a A database is made up of tables of information that are broken
relational database. down into records (rows of data) and each record has columns
of information about it (fields). To distinguish a particular record,
Choosing the software to create a database a unique data value has to be associated with it and is usually
structure just one separate field (column of data) but can sometimes be a
There are two types of software you could use to produce a combination of fields.
database:
A primary key is a field in a database that is unique to a
 Spreadsheet software particular record (i.e. a row in a table).
 Database software.
For example, in a table of children in a school, a record would be
You can build a simple database by organising the data the details about a particular student. A primary key would be the
in rows and columns in a table. In the table below the student number, which would be a number set up so that each
columns represent each of the fields and the rows are student is allocated a different number when they join the school.
the records. No two students would have the same student number.

Foreign key
A foreign key is used to link two tables together. A foreign key is a
field (or collection of fields) in one table that links to the primary
A flat file uses a single table of data set up like this. key in a different table.

183
Flat files and relational databases Three tables are needed to store this data and these can be called:
Computerised databases may be divided into two types: the
 Tools
limited flat-file database suitable for only a few applications, and
 Customers
the much more comprehensive and flexible relational database.
 Rentals.

Flat-file databases If the above were stored in a single table (in other words using
Flat-file databases are of limited use and are suitable only for very a flat file), there would be a problem. As all the details of tools,
simple databases. Flat files only contain one table of data. A record
is simply the complete information about a product, employee, KEY WORDS
student, etc. This is one row in the file/table. An item of information
Data redundancy where the same data is stored more
such as surname, date of birth, product number, product name,
than once in a table or where the same data is stored in
in a record is called a field. The fields are the vertical columns in
more than one table.
a table. Because flat-file databases contain only one table, this
Primary key this is a field that is unique for a particular
limits their use to simple data storage and retrieval systems such
record in a database.
as storing a list of names, addresses, phone numbers, etc. Tables
consist of columns and rows organised in the following way:
customers and rentals are stored together, there would be no record
 The first row contains the field names.
of a tool unless it had been hired by a customer. There would be no
 The rows apart from the first row represent the records in the
record of a customer unless they had hired a tool at the time.
database.
 The columns contain the database fields. In the flat file there would be data redundancy because
customer address details are stored many times for each time
The problems with flat-file systems they hire a tool. This means the same data appears more than
Flat files store all the data in a single table. The disadvantages of once in the one table. Hence there are serious limitations in
using a flat file are: using flat files and this is why data is best stored in a relational
database where the data is held in several tables with links
 Data redundancy. There is often a lot of duplicate data in the
between the tables.
table. Time is wasted retyping the same data, and more data
is stored than needs to be, making the whole database larger.
 When a record is deleted, a lot of data that is still useful may
Creating databases
Before you create a structure for a database, it is important to
also be deleted.
look at a sample of the data that needs to be stored.
 Harder to update as you may have to update the same
information in different places in the database. A school keeps details of all its pupils in a database. As well as
 Lack of data integrity. It is easy to forget to update data in all personal details (name, address, etc.), the school also holds
the areas in the database where it occurs. This can lead to details of the tutor group and tutors.
inconsistencies in the data held and staff can no longer rely
The person who is developing the database asks the principal for a
on the integrity of the data held.
sample of the data. This sample of the data is shown below:
 Lack of security as all the data is held together. This means a
person in personnel could see data relating to accounts. Description of data stored Sample data
Pupil number 76434
Relational databases Surname Harris
In a relational database, we do not store all the data in a single
Forename Amy
file or table. Instead, the data is stored in several tables with links
Date of birth 15/03/04
between the tables to enable the data in the separate tables to
Street 323 Leeward Road
be combined together if needed.
Town Waterloo
To understand this, look at the following example: Postcode L22 3PP
A tool hire business hires tools such as ladders, cement mixers, Contact phone number 0151-002-8899
scaffolding, chain saws, etc., to tradesmen. The following would Home phone number 0151-002-1410
need to be stored: Tutor Group 7G
Tutor number 112
 Data about the tools
 Data about the customers Tutor teacher title Mr
 Data about the rentals. Tutor surname Harrison
Tutor initial K

Three tables are used with the names: Pupils, Tutor Groups and
184 Tutors.
18 DATABA SES

KEY WORDS Tutor Groups


Relational database a database where the data is Primary key
Tutor Group
held in two or more tables with relationships (links) Tutor number Foreign key
established between them. The software is used to set
up and hold the data as well as to extract and manipulate Tutors
the stored data. Tutor number Primary key
Relationship the way tables are related or linked to each Tutor title
other. Tutor surname
Tutor initial
The fields in each table are as follows:
Pupils The data is put into three tables rather than one because it saves
Pupil number Primary key time having to type the same details over and over about the tutor
for each pupil. In other words it reduces data redundancy. If there
Surname
are 25 pupils in each form, the tutor’s details (Tutor number, Tutor
Forename
title, Tutor surname, etc.) would need to be entered 25 times. If
Date of birth
instead we put these details in their own table, we can access them
Street from the Tutor Group field and we then need type in the Tutor Group
Town details only once.
Postcode
Contact phone number
Home phone number
Tutor Group Foreign key

Q U E S T I ONS B SecondLineAddress Text/Alphanumeric


Postcode
1 A luxury car rental firm keeps the details of the cars it rents
LandlineNo Text/Alphanumeric
out in a table. The structure and contents of this table are
shown below. DateOfBirth Date
FreeSchoolMeals(Y/N)
Reg-number Make Model Year
a Give the most appropriate data types for
DB51 AML Aston Martin DB7 2009
the following fields: (3 marks)
CAB 360M Ferrari 360 Modena 2008 i Firstname
GT X34 FER Ferrari 355 Spider 2000 ii Postcode
MAS 12 Maserati 3200 GTA 2001 iii FreeSchoolMeals (Y/N)
FG09 FRT Porsche 911 Turbo 2009 b Give the names of three other fields that are likely to be
used in this database. (3 marks)
M3 MMM BMW M3 Conv 2010
c Explain which field is used as the primary key in the
T433 YTH Jaguar XK8 2009
database and why such a field is necessary. (2 marks)
a Give the field names of two fields shown in d It is important that the data contained in this
the table. (2 marks) database is accurate.
b Give the field name of the field that should be Describe how two different errors could occur
chosen as the primary key. (1 mark) when data is entered into this database. (2 marks)
c Explain why the field you have chosen for e Explain how the errors you have mentioned in
your answer to part b should be chosen part d could be detected or prevented. (2 marks)
as the primary key. (1 mark) 3 a Explain what is meant by a flat-file database. (1 mark)
d How many records are there in the table? (1 mark) b Explain what is meant by a relational database. (1 mark)
2 Most schools use databases to store details about each c Describe an application where a flat-file
pupil. The table shows some of the field names and data database would be suitable. (2 marks)
types stored in one pupil database. 4 Databases are of two types: flat file and relational.
Field name Data type a Describe two differences between a flat-file
UniquePupilNumber Number database and a relational database. (2 marks)
b A dress hire company needs to store details of
Firstname
dresses, customers, and rentals. They want to
Surname Text/Alphanumeric store these details in a database.
FirstLineAddress Text/Alphanumeric Which type of database do you suggest?
Give two reasons for your answer. (3 marks)
185
Linking files or tables (i.e. forming relationships) The advantages of relational databases
To link two tables together there needs to be the same field in Using a relational database means that you don’t have to type in all
each table. For example, to link the Pupils table to the Tutor the data for each pupil when you create the Tutor Groups table.
Groups table we can use the Tutor Group field as it is in both
This has the following advantages:
tables. Similarly, the Tutor Groups table and the Tutors table can
be linked through the Tutor number field. Links between tables are  It saves time typing.
often called relationships, and they are one of the main features  It reduces typing errors.
of relational databases.  It therefore reduces redundancy.
Choosing field names
Pupils
Field names should be meaningful to identify the field. Try to
Pupil number avoid using spaces in fields; instead use dashes or a combination
Surname of upper- and lower-case letters. Try not to make the fieldnames
Forename too long since these will be the column headings in the tables
Date of birth and if they are too long it will make the columns wide and not as
Street much data can be displayed on the screen at the same time.
Town Using the database to extract information
Postcode The Activities for this chapter on the website require the use
Contact phone number of database software. The suggested database software is MS
Home phone number Access 365. MS Access is a brand name so you have to make
Tutor Group sure that you do not write MS Access in an examination question
when the answer is ‘database software’. MS Access is popular
Tutor Groups database software but there are other examples of databases
Tutor Group that can be chosen.
Tutor number
On creating the tables, linking them and adding data, the data in
Tutors any of the tables can be combined together.
Tutor number A query is used to extract specific information from a database,
Tutor title so queries are used to ask questions of databases. For example,
Tutor surname a query could be used to extract the names of pupils in a school
Tutor initial who are aged 16 years or over. Queries are usually displayed on
the screen but they can be printed out if needed. If a printout is
needed, it is better to produce a report. A report is a printout of the
Foreign keys
results from a database. Reports can be printed out in a way that is
A foreign key is a field of one table which is also the key field
controlled by the user.
of another. Foreign keys are used to establish relationships
between tables. In the above example, the field Tutor Group
would be the key field in the Tutor Groups table and a foreign
key in the Pupils table.

186
18 DATABA SES

Activity 18.1
Locating, opening, and importing data from an existing file
In this activity you will learn how to:
 identify the structure of a csv file
 import a file in csv file format into database software
 change field names and data types
 change the structure of a database.
1 Load Microsoft Word and locate and open the file called Employees. This file is a comma separated variable (csv) file and a
section of it is shown here:

Notice that the first row of the data (which also appears on the next line because it is long) contains the field names.
Each subsequent row represents a record. Notice also that all the data is separated by commas.

Rather than type all this data into the database, we can create a database using this existing file.
Close the file without saving it and exit Word.

2 Load Microsoft Access and then click on and then .

Give the database the filename ‘Personnel_Database’ as shown here:

Click on .

187
3 Look at the following screen which appears:

Click on the External Data tab .

As a csv file is a text file, click on to tell the database software we want to import the data from a new data source
(i.e. the text file).

From the drop-down menu, select From file and from the next menu select Text file.

4 The Get External Data – Text File window appears. Click on Browse and find the file called Employees. Click on it to open it.
Check that the correct file is shown.
The data needs to be imported into a database table. Check that the first item in the list has been selected like this:

Click on OK.

188
18 DATABA SES

5 The following window appears:

Check that Delimited has been selected, as the data being imported has fields separated by commas, and then
click on Next.
6 The following window appears:

Check that Comma has been selected as the delimiter (i.e. what separates the fields in the file) and tick the box for ‘First
Row Contains Field Names’.
You are now going to check the data types for each of the fields to make sure they have been set up with the most
appropriate data type.
Click on .

189
7 The following window appears where you can check the field names that have been set up automatically:

Here you can make changes to the names of the fields and change the data types. You do this by clicking on the field name
and altering either the field name itself or the data type in the next column using the drop-down arrow.
Make the following changes:
Change the data type of the field ‘Salary’ to currency.
Change the data type of the field ‘Includes IGCSE Maths’ from Text to Yes/No.
Change the data type of the field ‘Includes IGCSE English’ from Text to Yes/No.
Change the data type of the field ‘Driving licence held’ from Text to Yes/No.
Change the field name ‘Includes IGCSE Maths’ to ‘IGCSE Maths’.
Change the field name ‘Includes IGCSE English’ to ‘IGCSE English’.
After all these changes have been made, click on OK.
8 Notice that the changes have been made in the window shown here:

Click on Next.

190
18 DATABA SES

A window appears and as there are no changes to be made, click Next again.
9 The following window appears:

Notice that a new field has appeared in the first column called ID. This is called the Primary Key and it is created
automatically to ensure that there is a unique field for each record (i.e. row of the table).
We want to choose the field Employee No as the primary key as this is a unique field in this table.
Select Choose my own primary key and use the drop-down arrow to select Employee No.
Click on Next.
10 The following window appears:

Here you give the table a name. The name suggested (i.e. Employees) is fine, so just click on Finish.

191
The following screen appears:

Click on Close to complete the import of the file to create a table of a database.
You will see the table listed on the left of the screen like this:

To open the table, double-click on it and the table is displayed.


The data is shown in Datasheet view and data can be changed in the table in this view.
To change the structure of the table you need to change the view to Design View.

11 You are now going to change the structure of the table.

Click on and then on and you will switch to Design View which shows the fields and their data types like
this:

Click on the Data Type for IGCSE Maths like this:

Now look at the Field Properties section:

Click on the box to the right of ‘Format’ and you will see a drop-down arrow from which you should select Yes/No.
Make similar changes to the following fields:

192
18 DATABA SES

IGCSE English
Driving licence held.
In the original csv file, the Salary field contained numbers so there was no currency symbol added.
To add the currency symbol, click on Salary in the list of fields and then click on format and use the drop-down arrow to
move to the required currency. Change the currency to Euro.
Currencies are normally expressed to two decimal places. As salaries are normally given as integers (i.e. whole numbers),
we need to change this so that numbers are given to 0 decimal places. Click on Salary in the list of fields and then click on
decimal places and use the drop-down arrow to select 0 decimal places.

Click on and then to view the data after the changes have been made.

You will now see the following box appear:

Click on Yes to save the changes made and the table containing the data will be displayed.

You can now close the database.

193
Activity 18.2
Importing data from an existing file and creating a relationship between two tables
In this activity you will learn how to:
 import data from an existing file
 create relationships between tables.
1 Load Microsoft Access and open the file Personnel_Database if it is not already open.

2 Click on then then From File and finally Text file.

Browse for the text file called Departments and import the file into a new table (note the steps to do this are identical to
steps 4 and 5 in Activity 18.1). Check that your file looks like this:

Check Delimited has been selected and click on Next.


The next window appears:

194
18 DATABA SES

Select the delimiter Comma as we are importing a comma separated variable (csv) file and also select First Row Contains
Field Names and click Next.
The following screen appears:

There is nothing to change here, so click Next.


The following screen appears.

195
Click on Choose my own primary key and then select Dept from the drop-down list.

This will set the field Dept as the primary key.


Click on Next.
The final step is to import the data to the table called Departments.

Click on Finish.

3 Click on Departments in the list of tables.

196
18 DATABA SES

At the above, click on Close.

The table now appears in the list of tables. Double-click on to view the data.

Check that your table contains the following data:

Close the tab by clicking on the cross.


4 You are now going to establish a relationship (i.e. link) between the Employees and Departments table. Close any tables

currently open. Click on and then .

Click on Departments

and then on .

197
Now click on Employees and then on .
Both tables are added like this:

Click on the corner of the Employees table and drag so that it is positioned to the left of the other table. Also enlarge this table
so that all the fields can be seen.
The tables should now look like this:

Click on Dept in the Departments table and keeping the left mouse button pressed down, drag to the Dept field in the
Employees table. The following window appears.

Ensure that the box for Enforce Referential Integrity is ticked and then click on .

198
18 DATABA SES

This will ensure that employees cannot be linked to a Department which does not exist.
The relationship between the fields in each table now appears like this.

Click on and when prompted to save the relationship, click on Yes.

Manipulating data
Activity 18.3
Entering data with 100% accuracy, showing subsets of data, and sorting data
In this activity you will learn how to:
 enter data into a database with 100% accuracy
 adjust the column widths so all the field names are visible
 show subsets of data
 sort data.
Data can be entered straight into a table and you may be asked to add data to existing data in the examination. The data you
add can be added at the end of the table and must be entered with 100% accuracy. This means you must visually check what
you have typed by comparing it with what is written on the examination paper. If you make mistakes in your data entry, it will
cost you marks.
1 Load Microsoft Access and open the database file called Personnel_Database.

Double-click on the Employees table: .

2 You will notice that some of the field names and data items are not fully visible:

Move the cursor on the line which separates the field names. You will see it change to a double-headed arrow. Now drag
the line until the whole field name is shown along with the data in the column below it. Repeat this process for those field
names and data that are not fully shown.
3 At the end of the table enter the following new records.

Visually check the records you have added and ensure you have achieved 100% accuracy. Save this new data by clicking
on then Save, or by the keyboard shortcut Ctrl-S.

199
4 You are now going to use a query to select certain fields to show and also put them in descending order of salary (i.e. with
the largest salary first).

Click on the Create tab and then click on Query Wizard .


The first window of the Query Wizard appears:

Check that Simple Query Wizard has been selected and click on OK. The next window appears. This is where you select a
table and the fields in that table you want displayed in the query.

Make sure the Table: Employees is selected and then add the fields in the Employees table by clicking on each of the
following fields followed by .
Surname
Forename

200
18 DATABA SES

Salary
Full or part time
Now click on the drop-down arrow to select .

Add the Description field in the Departments table by clicking on the field followed by .
When all the fields have been added, click Next.
The next window appears:

There is nothing to change here, so click on Next.

Change the title for the query to Query Salaries. Click on the button for Modify the query design and click .
The query design is now shown:

201
Move the cursor to the Sort box for the Salary field and click on the drop-down arrow and select Descending. This sorts all
the data in order of salary with the highest salary first.

Click on Home and then View to view the results of the query:

Click File and then Save to save the query.

202
18 DATABA SES

Activity 18.4
Performing searches using queries
In this activity you will learn how to:
 perform searches using numeric data with operators, e.g. =, <, > , >= and <=.
In this activity you will be using a query to make a list of only some of the records, i.e. the employees who do not have IGCSE
Maths. Also, you only want some of the fields for these employees and not all of them.
1 If you do not have the Personnel database already loaded, load Microsoft Access and open the database file called
Personnel database. Click on the Employees table to select it.

2 Click on the tab and then click on Query Wizard .

Here is what you need to select for each one. Simple Query Wizard and then click on OK. Select the fields Forename,
Surname, IGCSE Maths and Position from the Employees table.

Select the field Description from the Departments table when the selected fields section will now
appear as follows:

Click on Next.
Select and then click Next.

3 Enter the following name of the query:

The purpose of this query is to give information about those employees who do not have IGCSE Maths, so this query name
describes the purpose of the query.
Select and click on .

4 In the Criteria box for the field IGCSE Maths enter No:

203
5 To display the results of the query, click on Home and then View. Note that in order to see the data in some fields fully, you
will need to widen some of the columns.

6 To close a query, click on the cross at the top right of the query tab.

If you are asked to save your query, click on Yes.

7 You now have to follow similar steps to the above to create a new query that must display the following fields:
Forename
Surname
Position
Salary
Dept
Give the query the name Query High pay. The purpose of the query is to show those fields outlined above for all the
employees who have a salary of over 40000 and also to organise the data in descending order (i.e. with the highest
salary first).
When you get to the query design screen, you need to insert the details in the criteria for the Salary field box >40000 and
also click on the Sort box and select Descending using the drop-down arrow.

Click on Home and then View to see the results and check that they are correct. Save and close this query.

204
18 DATABA SES

Activity 18.5
Performing wildcard searches Note that even though this field is formatted to currency
In this activity you will learn how to: you should not include the currency sign with the
 perform searches using multiple criteria number in the search criteria. Notice also that because
 perform searches using wildcards. two criteria are being used, the data has to meet both
criteria (i.e. contain the word ‘admin’ for Position AND
1 Load Microsoft Access and load the file Personnel_
have a Salary of 26000 or less). Run the query by
Database if not already loaded.
2 Click on the Employees table and create a query clicking .
containing all the fields. Give the query the name Query
Admin.
3 In the Criteria box for the field Position enter the following 5 Go back to Design View and delete all the search criteria.
wildcard: 6 You have been asked to show all the details for those
employees who are not programmers. For the Position
field enter the criteria Not programmer like this:

When you enter the formula it changes to the following:


. When you press Enter it changes to the following:
This wildcard will select all those fields where the text
‘admin’ appears in any part of the data for the position
field.

Click on and the results are shown. Check that

the Query is working and finds the correct number of


employees and that they all have the letters ‘admin’ in Run the query and the results are shown. Check that the
their Position. results are correct – all the records do NOT have the word
4 You are now going to alter this query to show only those Programmer.
employees with ‘admin’ in the title for their position AND 7 Close the query without saving.
with a salary of 26000 or less. Click on the criteria for
Salary and enter <=26000 like this:

205
Activity 18.6
Putting formulas in queries
In this activity you will learn how to:
 put formulas in queries.
1 Load Microsoft Access and load the file
Personnel database if not already loaded.
2 Create a query containing all the fields in the Employees
table and call this query Query showing pension.
3 Ensure you are looking at the Design View of the query.
The company has a pension scheme where each
employee must pay 8% of their salary into the scheme.
A formula is needed to calculate 8% of the Salary for each In the Property Sheet section, click on the drop-down
employee. arrow for Format and change it to Euro like this:
Before entering the formula, you should widen the
column where the formula is to go so that all the formula
can be seen.
In the first blank field enter the following formula:
Pension:([Salary]*8/100)
After entering the formula, make sure that the box is
ticked to show the results of the calculation.
Now change Decimal Places to 0.
5 Go back to the View to see the results of the query.
6 Save this query.

Important notes about this formula:


 Pension is the name of the new calculated field.
 Any fields used in calculations must be surrounded by
square brackets.

4 Click on to see the results of the query. There is a

problem because the data calculated looks like this:

The calculated Pension field needs to be formatted to

currency. Go back to the Design by clicking and

right-click on the calculated field and select Properties


from the following menu:

206
18 DATABA SES

Activity 18.7
Performing searches on the Employees database 6 A list of the fields: surname, position and salary for all
In this activity you will learn how to: employees who are not programmers.
 perform searches using multiple criteria 7 A list of the fields: surname, forename, position and room
 use Boolean operators in searches where the position contains the word ‘clerk’.
 sort data using one criterion into ascending or 8 A list of the fields: surname, position and salary for all
descending order. employees who have the words ‘clerk’ or ‘analyst’ as part
For this activity you are required to produce queries on the of the position field.
Personnel_Database to extract the following data: 9 A list of the fields: surname, position and salary for
1 A list of the fields: surname, forename, sex and position all employees earning 40000 or over arranged in
for all female programmers. alphabetical order according to surname.
2 A list of all employee numbers, surname and forename 10 A list of the fields: forename, surname and position for all
for employees who work part time. female workers who earn over 30000. This list needs to
3 A list of the fields: surname, forename, salary, description be sorted in descending order according to salary.
and sex for all employees earning less than 20000. 11 A list of the fields: employee no, surname, forename for
4 A list of the fields: surname, forename and position for all the staff who work in room A2.
all employees who are either web designers 12 A list of the fields: employee no, surname, forename for
or programmers. all staff who are programmers and who have a driving
5 A list of the fields: surname, forename, position and licence, arranged in alphabetical number according
number of IGCSEs for all the employees having less than to surname.
or equal to three IGCSEs.

Presenting data
Activity 18.8
Producing reports
In this activity you will learn how to:
 produce reports to display all the required data and labels in full
 set report titles, use headers and footers, align data and labels appropriately.
A database report is the printout of the output from a database. Reports are professional-looking documents and you have
more control over their appearance rather than simply printing out query results.
1 Load Microsoft Access and open the file Personnel_Database. This report is going to be based on one of the queries you
have already produced and saved. Select in the All Access Objects section on the left of the
screen.
2 Click on Create and then look for the Reports section shown here:

Click on .

207
3 The results of the query are made into a report which is now displayed:

4 We will now change the orientation of the report. You will be told in the examination paper which orientation to use. Here
you will need to change the orientation to Landscape.

Click on in the main toolbar and click .

5 Double-left-click on the report title when it will appear like this .


Change the title of the report to ‘Details for all employees earning over 40000 Euros’.
The text appears like this:

Left-click near the edge of the box to select it. When selected, the border will look like this:

Now click on the right vertical edge of the box, when you will obtain a double-headed arrow which you can then use to
stretch the box until it looks like this:

The aim of this is to fit the title onto a single line.


6 We are now going to change the design of the report. Click on and then on the drop-down arrow on

and select .
208
18 DATABA SES

The design view is shown:

Notice the way the report is divided into sections:


 Report header – this is used for a title and any other information for the whole report as it only appears once at the
start of the document. You must obey the examination instructions as to what to put into the header.
 Page header – this appears at the top of each page and is used to hold the fieldnames.
 Detail – this shows the rows of data.
 Page footer – this is used to hold details such as the date the report was produced, who produced it, page numbers,
etc. Always obey the examination instructions carefully as to what to put into the footer.
You have been asked to enter your own name on the right in the footer.
Room needs to be made in the Page Footer section for this. To create this room, move the cursor onto the Page Footer
section just before the Report Footer section and you will see it changes to a double-headed arrow like that shown here:

Press the left mouse button down and keeping it pressed down, drag down so that it now looks like this:

Check that has been selected and then look at the controls section:

You need to create a Label to contain your name.

Left-click on and move the cursor to the position shown here:

209
Keeping the left mouse button pressed down, drag the cursor to create the label to look like this:

Enter your own name into the label:

Highlight your name to select it:

The name is to be right-aligned so click on Home and then the right-align button .
Your name will appear like this:

Click on and then .

210
18 DATABA SES

You can see from the report that the data all appears on the report. Always check that the field names and the data in the
fields are all visible.
There are a few things we can alter. The report has a total added for total salary which was added automatically. This
requires deleting. It would look better if the page number were right-aligned, like your name. The headings and data for
Salary and Dept are too close.

Click on and then Design View.


Right-click on the formula to add up the salary and then from the drop-down menu select Delete.

Notice there is still a line where the formula was . To delete it, right-click on the line but make sure
there is only the orange box around the line and from the drop-down menu select delete.
Now left-click on the page number info so that the box is selected like this:

Now ensure that the cursor has changed to this and drag the box into

the position shown here.

To right-align the page numbers, highlight the text in the box like this:

Click on and then right-align .

Now click on and to check that the report looks like this:

211
7 Go back to the design of the report by clicking then .
Click on the Dept box in the Page Header section to select and move the cursor onto the right-hand side of the box where it
changes into a two-headed arrow like this:

. Drag the edge of the box to the left until it looks like this:

Notice that the Dept box in the Detail section underneath the fieldname is adjusted automatically.
Now view the report. It looks like this:

In a similar way to the above, reduce the widths of the other fields as shown here. Also line up the boxes containing the
page numbers and your name in the page footer so that the right side of the box is aligned with the right side of the box for
the Dept field.

212
18 DATABA SES

Check the appearance of the report by looking at it in Report View. It should look similar to this:

8 We are going to right-align the field name and the fields for Dept.
Go to Design View and position the cursor on the top of the box for the fieldname Dept like this:

When you do this, you will notice that both boxes are selected.

Click on right-align and the fieldnames and fields are now right-aligned .
9 We need to adjust the Salary field so there are no decimal places shown.
Click on the Salary in the Detail section. Only this book should be selected like this:

To adjust the decimal places, click and then to show the salary with no decimal places.
10 We will now adjust the heading. Click on the heading in the Report Header.

213
Now click on the right of the box and drag the edge so that it is lined up with the right edge of the Dept field like this:

Now highlight the text:

Click on to make the text bold and then click to centre the heading within the box.
Check your Report Header looks like this:

11 Click on Home and then on and then Report View to see the final report:

Close the report by clicking on the positioned on the pink tab. The following appears:

214
18 DATABA SES

Click Yes and the following window appears:

Type in the report name Report High Pay and then click OK to save the report.

Activity 18.9
Producing calculations at run time
In this activity you will learn how to:
 create calculated fields
 perform calculations at run time
 format fields.
One way of performing a calculation on data in a database is to create a calculated field which is worked out in a calculation
performed on other fields already in the database. This is called a calculation produced at run time.
1 Load Microsoft Access and open the file Personnel_Database.
2 The company has decided to give all the employees a 5% pay rise. You have been asked to produce a query that shows the
fields Employee No, Surname, Description and Salary, along with two new calculated fields.
One of these calculated fields is to be called Pay rise and the other is to be called New salary.
As we are going to use the fields in the two tables to create the query, click on:

Create a query by clicking on and then on .


Select Simple Query Wizard and click OK. Now add the following fields in the same order as shown here (note you will need
to use the fields from both tables so remember to change the tables).

215
Click Next and at the next window also click Next.
Now change the title for the query to: Query Pay Rise and ensure you have selected Modify the query design.

3 Click on Finish and the query design will be shown:

In the first row of the first blank column enter the following formula:
Pay rise: [Salary]*5/100
There are some important points to remember with formulas:
 The new fieldname is written to the left of the colon (:).
 Fieldnames that are used in the formula are identical to those used in the database.
 The fieldnames used in formulas must be enclosed in square brackets.
Adjust the width of the column so that the entire formula can be seen like this:

In the next blank column enter the following formula to calculate the New salary:
New salary:[Salary]+[Pay rise]
Make sure you put a tick in the box to show the data for this calculated field.
Widen the column containing this formula so that all of it is shown like this:

4 Click on Home and then View to see the results of the query.
Notice that the Pay rise field is not formatted correctly.
Go back to the Design View and right-click the mouse button on the Pay-rise field:

216
18 DATABA SES

The following menu appears, from which you should select Properties.
The Property Sheet appears on the right like this:

Click on Format and click on the drop-down arrow and select Euro from the list.
Click on Decimal Places and click on the drop-down arrow and select 0 from the list.

You have now formatted this field.


In a similar way, format the New salary field.
Just because you see numbers inserted in the correct place, do not assume they have been correctly calculated. It is easy
to make mistakes with formulas. Check the calculations manually with a calculator to ensure the output is correct.
5 Click on Home and then View to see the results of the query and check that they are correct. Make sure all the field names
and fields are shown correctly without parts being cut off. You may need to adjust the widths to make this so. Your query
should look similar to this:

Save and close the query.

217
Activity 18.10
Creating the report based on the query
In this activity you will learn how to:
 create totals of columns of numbers using SUM.
1 Load the database software and open the file Personnel_Database if it is not already open.
2 Single left click on and then click on and then Report.
3 Click on the query called ‘Query Pay Rise’ created in the last activity.
Click on Design View.

Click then .

Right-click on Salary in the Page Header to select it and a drop-down menu also appears. Select
descending. The data will be sorted into descending order according to Salary.
Click Home and then View to check that the data has been sorted correctly.

4 Go back to Design View and click on and then .

Click and one of the themes shown . A theme is a combination of suitable


fonts and colours for the report.
5 View the report and then go back to the report and make any necessary adjustments to the field names or the fields so
that all the data is shown without any being cut off.
6 Stretch the box containing the text ‘Query Pay rise’ so that it fits to the right margin of the report and change the text in the
Report Header to ‘Report showing a 5% pay rise for all employees’.

218
18 DATABA SES

Make the text bold and centre it. It should look similar to this:

7 Notice there is already a calculation that has been automatically added to the report. This calculation =Sum([Salary])
adds up all the salaries in the Salary column.
You are going to put some calculations in the Report Footer section of the report.
Click on the horizontal line at the end of the Report Footer section and you will see the double-headed arrow. Drag this
down until it looks like this:

As we want to design our formulas from the start, we need to delete the formula that has been added automatically.

Right-click on the formula to highlight it like this and from the drop-down menu, select Delete.
Notice a line is still left behind. This needs to be deleted in the same way.

8 Click on and then on and drag it to produce a text box below the Salary column.
You may need to adjust this box so it looks like this:

There are two boxes: one box to hold text explaining what the contents of the other box represents and the other to hold the
result of the calculation.
The box on the right is called a control and this will be used to work out the total of the old salary for all the employees.
Double left-click on the label (i.e. the box on the left) and you will see the Property Sheet appear down the right-hand side
of the screen.

219
Click on the All tab in the Property Sheet.
In the Caption box, type the text ‘Total of old salary’.

Move this box to the left so it appears like this:

Click on the Controls box (i.e. the box containing the text Unbound) to select it like this:

Select the Data tab of the Property Sheet and in the box to the right of Control Source enter the following formula:
=SUM([Salary])

Notice the following:


 The formula starts with an equals sign.
 The formula is enclosed between two curved brackets.
 Any fields to which the formula refers must be in square brackets.
Click on Enter and you will see the formula inserted in the control box like this:

9 Create two similar text boxes with the following text and formulas:
Total cost of pay rise =Sum([Pay rise])
Total of new salary =Sum([New salary])
They should appear like this:

220
18 DATABA SES

10 Click on Report View to see the results of the report. The totals are shown but they are not in currency format.

11 Click on Design View. If the Property Sheet is not shown on the right, then right-click on the first control containing the

formula: .
Look at the Property sheet on the right of the screen.
Click the Format tab if Format has not been selected and make the following changes.
From the drop-down menu for Format select Euro. Now click on Decimal places in the menu and select 0.
Repeat this process for the two other controls.
You will now have set the calculation fields to currency (Euro in this case) and to zero decimal places.

Click on Report View and you will see all the totals correctly formatted:

12 Save your report using the filename Report Pay rise.


13 You have been asked to provide evidence of the design of your report.
Open your report.
Click on Design View so that you are looking at the design of your report.
Take a screenshot of the entire screen by pressing the Print Scrn key.
Load Microsoft Word and create a new document.

Position the cursor a couple of lines down from the top of the blank document and click on .

221
You will see the screenshot inserted into the document like this:

You cannot see the formulas easily, so it is necessary to crop the image (i.e. only use part of it) and then enlarge the
remaining part.
Right-click on the image (i.e. the screenshot) and a menu appears.

Click on and you will see the image changes to:

222
18 DATABA SES

Drag the black handles so that only the report design part of the image is shown like this:

Add your name to the document and then save it using a suitable file name.
Print a copy of this document.

Activity 18.11
Showing and hiding data and labels within a report
In this activity you will learn how to:
 show and hide data and labels within a report.
1 Load Microsoft Access and open the file Personnel Database.
Open the Report Pay Rise by clicking on it in the All Access Objects section:
2 Change the view to Design view to display the design of the form.
3 Sometimes field names, fields or labels need to be hidden.
Here you are going to hide the Salary and New salary details in the report.
Keeping your finger pressed down on the shift key, left-click on all the following boxes to select them in the Page Header
section and Detail section of the report:
When they are all selected, they will have an orange border and look like this:

Clicking both boxes for each pair of fields ensures that both the fieldname and the data in the field are hidden.
4 Look at the Property Sheet on the right of the screen and select the Format tab if it is not already selected:

Click on the drop-down arrow for the Visible property and select No. This will hide all the items selected.
5 Click on the Report View. The report now appears with the selected items hidden:

223
6 You are now going to show the hidden data.
Go back to the design view where you will notice that there are fieldnames and fields that were not visible in the report.
Select all the headings and fields that did not appear in the report and go to the Property Sheet and change Visible to Yes
like this:

Click on the Datasheet View and the report will now be shown with the previously hidden items displayed.
7 Another way to hide data is to make the background colour the same as the text colour.
You are now going to change the background colour to black for the first column of data. The column heading is kept but
the data below it will look like a black column so it cannot be seen.
Left-click on Salary in the detail section like this:

Look at the Property Sheet down the right of the screen and click on Format.
Look down the list until you find the following

Click on the three dots next to the drop-down arrow and a palette of colours is shown:

Click on the black colour in the Standard Colors section to set this as the background for the selected field.

224
18 DATABA SES

8 Go to Report View and you will see the field for Salary with the black background like this:

However, there is a problem. You can still make out the amounts as the text colour is not completely black, so it shows
slightly. This is easy to correct. We just need to make the text black rather than a shade of grey.
Go back to the Design View and ensure Salary in the Detail Section is selected.
Look at the Property Sheet section and click on Format and look down at the list for Fore color.

Click on the above and then click on the three dots to obtain a palette of colours.
Select black.
9 In a similar way, hide the fields for New Salary.
10 Go to Report View and you will see the field for Salary and New Salary obscured like this:

10 Click on the cross on and the following window appears:

Click Yes.

Activity 18.12
Database labels
In this activity you will learn how to:
 produce labels that can be printed out.
1 Load Microsoft Access and open the Personnel_Database.
2 You are going to produce labels arranged in two columns for all staff who work full time and who work in the Sys or
Prg departments. The only fields to be shown on these labels are Forename, Surname, Position and Department, all on
separate lines. It has also been decided to include the field names next to the data on each label.
You first need to create a query to extract this information from the database and this query is then used as the source of
data for the labels.

Click on and then . Choose Simple Query Wizard and then click on OK.

225
Using the Employees table as the source of the fields, select the fields Forename, Surname, Position, Dept and Full or part
time. Click Next.
The next window appears from which you should enter the following name for the query: Label query. Also make sure that
Modify the query design is selected.

Click Finish.
3 The query design now appears. Enter the following criteria which will ensure that the query only extracts the data for
employees who work full time and who work in either the Sys or Prg departments.

4 Click on Home then View and use the drop-down arrow to select Datasheet View. Check that the data being extracted is
correct by comparing it with the following:

Save your query using the name Label query.

5 Make sure that the query in the All Access Objects section is selected if it isn’t already as you
are going to use the fields in this query as the basis for the fields on the labels you are going to create.

226
18 DATABA SES

6 Click on and then . The following window appears from which you need to select the labels that
have the dimensions 72mm × 72mm and are 2 across.

Click on Next.
7 In the window that appears, make the following changes to the text as shown here.

Click Next.
8 The following window appears:

227
Type in the field name Forename:
This will appear just as ordinary text on all the labels.
The label will now look like this .
Leave a space and then click on Forename in the Available fields and click on to add the field to the label so that the

label becomes .
Now do the same for the fields Surname, Position and Department so the label is the same as that here:

Click Next when another window appears. As we do not need to do any sorts, click Next.
A window appears. Make the settings the same as those shown here:

Click Finish.
9 The design of the query is now shown.

228
18 DATABA SES

10 Move the bottom of the grid up so it now looks like this.

11 To check the way the labels will be printed, click on Home and then on the drop-down arrow for View and finally on Print
Preview. The labels are now shown as follows:

12 Click on Print to print the labels out.


13 Click on Close and when prompted to save the file, select Yes and use the filename suggested.

Activity 18.13
Creating a data entry form
In this activity you will learn:
 key features of form design
 creating a data entry form
 using font styles and sizes, spacing between fields and character spacing in fields
 use of radio buttons and drop-down menus.
Data can be entered straight into a table, but it is better to create a data entry form for the entry of data. The purpose of a data
entry form is to make it easy and quick to enter data into the database. For example, a button called a radio button can be used
for those fields having only yes/no possibilities. If the button is filled in, it means yes, and if it is empty, it means no. Also,
you can set up drop-down menus so that a user can select from a list of items when they are entering data where there is a
restricted number of possibilities.
Forms are used to view data or enter data into a table or tables. In this activity, you will be creating a data entry form for the
entry of data into the Employees table.

229
1 Load Microsoft Access and the Personnel_Database if not already loaded.

2 Click on and then and in the field list on the right of the screen click on Show all tables.

The available tables are shown.


Click on the + for Employees when the following fields are shown:

3 In the above list of fields, double-left-click on the fields Employee No, Forename, Surname and Sex in turn and they will be
added to the form like this.

You are looking at the form in Layout view which shows how the form will look on the screen with data added.
Change the view of the form to Design View by clicking on and then on the drop-down arrow for View where you
should select Design View.

230
18 DATABA SES

Click at the bottom of the form where the cursor changes into a double-headed arrow and keeping the mouse button
pressed down, drag down to increase the length of the form. Increase the length to about 9 using the vertical ruler.
4 Click on the right box (called the control) for the Sex field. When selected, the field looks like this:

Press Delete to delete the control. Note that both boxes are deleted.
5 You are now going to replace this with a combo box (also called a drop-down menu) which will allow the user to either
choose M or F. This restricts what the user can type in, so it is a good method of data validation.

Click on and then on which is the button for the combo box.
When on the form, the cursor changes to a + with an icon for the combo box attached. Click under the control box for
Surname and drag to produce two boxes. One of these boxes is for the control and the other is for the label.
When you release the mouse button, a window appears from which you should select the following:

and then click Next.


6 In the next window you can enter the values you want the user to select from.

Type in M and F as shown here, then click Next.


In the next window we need to tell the system the field to put the entered values into.

Check these selections are made and click Next.


In the window that appears, you are asked for text that will appear as the label.

Enter Sex: like this and click on Finish.


Move the control and its label so it is aligned like this.

7 Add the fields DOB and No of IGCSEs onto the form. To do this, click and then click . Add the
fields from the list of fields to the form by double-clicking on them. You may need to move the labels and controls into the
positions on the form as shown below. Note that combo boxes are not being used for these fields.

231
8 Now add the IGCSE maths field by double left-clicking on it in the Field List. Now move it to below the field No of IGCSEs.
You will need to reposition it so it is in a similar position to that shown here:

Now in a similar way, add the IGCSE English field and position it below the IGCSE Maths field.
9 Now add the Position and Salary fields. These are just ordinary controls with their labels. Your form will now look like this:

10 Now create a combo box for the Full or part time field below Salary. The alternatives for the combo box should be F or P and
this data should be stored in the Full or part time field.
11 You are now going to use a radio button to indicate whether a person has a driving licence or not. Add the control and label
for Driving licence held in the position shown here.

Now delete the control and label and click on and then on the radio button which is called an option
button by Access.

232
18 DATABA SES

Now click on the form to add the button and its label positioned below the boxes for Driving licence.
Add the text Driving licence held: to the box containing the label.

Click on the button to select it . You will notice the Property sheet appears on the right of the
screen.
Select the Data tab and then use the drop-down arrow to select Driving licence held as shown here:

12 Click on and then so that you can add the final field to the form.
In the list of fields, double-click on Dept to add it to the form.
Select the control and label and delete it using the Delete key.

Click on and which is the icon for a list box and draw a box underneath the field for Driving licence held.

From the window that appears select .


This will allow you to create a list of all the departments and allow the user to choose one of them. This makes things
easier for the user as they do not have to remember all the departments and type one of them in. It will also restrict what
can be entered and this will reduce errors.
Click on Next.
Click on Departments and then on Next.

Add Dept to the selected fields:


Click on Next.
At the next window there are no alterations so click on Next.
The list is now shown like this.

Click on Next.
A new window appears. Make the following changes.

233
Click on Next.

At the next window add the following text for the label .

Click on .

13 It has been decided that it would be better to have a check box rather than a radio button to show whether an employee
has a driving licence or not.
To change the radio button, right click on it and from the drop-down menu select Change to:

A new drop-down menu appears from which you should select the check box like this:

234
18 DATABA SES

The check box appears:


14 View the form in Form view. It should appear like this:

You need to check that all parts of the form behave as expected by looking at each record in turn.
15 You are now going to rearrange the fields on the form so that there is more white space between them. Adding white space
will improve the appearance of the form. Click on the bottom right of the workable area of the form and the cursor will
change to:

Now drag until the form looks like this:

You can now click on the fields and move them around.
It is up to you where you position each of the fields, but the more important fields should be at the top of the form and on
the left.
Save your form using the file name Data entry form.

235

You might also like