Database Notes
Database Notes
13.1 Introduction
A DATABASE is a structured collection of data that allows people to extract
information in a way that meets their needs. The data can include text, numbers,
pictures: anything that can be stored in a computer.
Databases are very useful in preventing data problems occurring because:
• data is only stored once – no data duplication
• if any changes or additions are made it only has to be done once – the data is
consistent
• the same data is used by everyone.
Activity 13.1
Find five more uses for databases, and for each one decide what sort of
information is being stored.
250
Figure 13.1 Structure of a database table
Tables contain data about one type of item, person or event, for example:
• a table of patients
• a table of books
• a table of doctor’s appointments.
Each record within a table contains data about a single item, person or event, for
example:
• Winnie Sing (a hospital patient)
• IGCSE Computer Science (a book)
• the 15:45 appointment on 27 January 2014.
Each field contains one specific piece of information about a single item, person or
event, for example:
• For a hospital patient the fields could include:
• first name
• family name
• date of admission
• consultant
• ward number
• bed number.
• For a book the fields could include:
• title
• author
• ISBN.
Activity 13.2
What fields would you expect to find in each record for a doctor’s
appointments?
In order to be sure that each record can be found easily and to prevent more than one
copy of the same record being kept, each record includes a PRIMARY KEY field. Each
251
primary key field in the table is unique.
The primary key can be a field that is already used, provided it is unique, for
example the ISBN in the book table, or a new field added to each record, for
example, a unique hospital number could be added to each hospital patient’s record.
Sometimes, a primary key can be formed by using two or more existing fields, for
example, the doctor’s appointments could have a primary key made from the date and
the time of each appointment.
Case study
Boys and girls between the ages of seven and eleven can join a cub scout
group. (http://en.wikipedia.org/wiki/Cub_Scout)
Each cub scout group needs to keep records about its members. Most
groups will keep the following information about each cub in their group:
Personal Details Form
To ensure our records are up to date, please fill out all of the information
below. Without a completed form, your child will not be able to participate in
meetings/activities.
252
Personal Details
Name:
Date of Birth::
Address:
Gender:
School:
Telephone Number:
Date Joined:
Figure 13.3 Data collection form
To create the cub scout database, open Access, select the Blank database
template
and type the filename CubScout and click the Create button.
253
Figure 13.5 Creating the cub scout database
254
and name the table Cub.
Set up the fields to match the data collection form and include the primary
key. Each field will require a meaningful name and a data type must be
selected. The basic data types were introduced in Section 11.4. They are
available in Access but the names are different.
Access also has other data types that will be useful: Date/Time and
Currency.
255
Figure 13.8 Cub table fields
Access allows validation checks to be built in for each field, for example the
gender field:
Activity 13.3
Decide which other fields should be validated.
The cub scout leader wants to be reminded before the first meeting in the
month of any cub scouts who will have a birthday that month.
To set up a query-by-example to perform this task, open the database
CubScout, select the Create tab followed by Query Design.
256
Figure 13.10
Figure 13.11
The cub scout leader wants to see the Name of any cub with a Date of
Birth this month.
Select the fields Name and Date of Birth, check the box to display the
Name and check that the month of the Date of Birth is the same as the
current month.
257
Figure 13.12
Figure 13.13
Activity 13.4
Set up a cub scout database with 10 records in it. Include appropriate
validation. Using query-by-example, write a query to pick out any cubs born
this month.
The cub scout leader wants to put each cub into a group called a ‘six’. Each
‘six’ can have up to six cubs in it and is given a name, for example red,
258
yellow, blue or green. Add a new text field called Six, put each cub into a
six. Using query-by-example, write a query to pick out any cubs in the red
six.
259
End-of-chapter questions
1 A database of students is to be set up with the following fields:
• Family name
• Other names
• Student ID
• Date of birth
• Date of entry to school
• Current class
• Current school year/grade
• Email address.
a Select a data type for each field.
b Which fields should be validated and which fields should be verified?
c Decide the validation rules for those fields which should be validated.
d Which field would you choose for the primary key?
e Choose a suitable format for the student ID.
f Build a database with at least 10 records. Include all your validation checks.
Ensure there are at least three different classes and two different years/grades.
g Set up and test QBEs to:
i Print Other names, Family name and Email address in alphabetical order of
family name
ii Select all the students from a given class
iii Select all the students for a year/grade and print Other names, Family name and
Data of birth, grouping the students by class.
2 A motor car manufacturer offers various combinations of
• seat colours
• seat materials
• car paint colours.
A database was set up to help customers choose which seat and paint
combinations were possible.
260
Figure 13.14
Figure 13.15
261
Figure 13.16
Figure 13.17
262
Figure 13.18
263