Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
2K views

Database Notes

The document describes a database about cub scouts. It discusses defining a database with fields for personal details like name, date of birth, and address. Each record would have a primary key for identification. Queries can extract specific records, like finding cubs with upcoming birthdays. The database is demonstrated with an example of setting up a cub scout database in Microsoft Access, including defining fields, entering sample records, and writing queries.

Uploaded by

Thapelo Jeremiah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Database Notes

The document describes a database about cub scouts. It discusses defining a database with fields for personal details like name, date of birth, and address. Each record would have a primary key for identification. Queries can extract specific records, like finding cubs with upcoming birthdays. The database is demonstrated with an example of setting up a cub scout database in Microsoft Access, including defining fields, entering sample records, and writing queries.

Uploaded by

Thapelo Jeremiah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

13 Databases

In this chapter you will learn about:


• what databases are used for
• database structure
• practical uses of a database.

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.

13.2 What are databases used for?


To store information about people, for example:
• patients in a hospital
• students at a school.
To store information about things, for example:
• cars to be sold
• books in a library.
To store information about events, for example:
• hotel bookings
• results of races.

Activity 13.1
Find five more uses for databases, and for each one decide what sort of
information is being stored.

13.3 The structure of a database


Inside a database, data is stored in TABLES, which consists of many RECORDS and
each record consists of several FIELDS.

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.

Figure 13.2 Structure of a database table including a primary key

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.

13.4 Practical use of a database


As a Cambridge IGCSE Computer Science student you need to be able to do the
following:
• define a single-table database from given data storage requirements
• choose a suitable primary key for a database table
• perform a query-by-example from given search criteria.
In order to do this you will need to use a relational database management system. The
following case study shows how to set up a database with Microsoft Access and
complete the tasks described above.

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

13.4.1 Defining a database


This section shows you how to define a single-table database from given data storage
requirements and choose a suitable primary key.

To create the cub scout database, open Access, select the Blank database
template

Figure 13.4 Blank database

and type the filename CubScout and click the Create button.

253
Figure 13.5 Creating the cub scout database

Select the table design view

Figure 13.6 Design View

254
and name the table Cub.

Figure 13.7 Naming the table

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.

Computer program Access


Integer Number/Integer
Real Number
Char Text/field length 1
String Text
Boolean yes/no
Table 13.1

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:

Figure 13.9 Gender field validation

Activity 13.3
Decide which other fields should be validated.

13.4.2 Getting information from a database


This section shows you how to perform a query-by-example (QBE) from given
search criteria.

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

Then add table Cub.

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

Then run the query to test it.

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

a How many records are shown in the database?


b The following search condition was entered using a query-by-example grid:

Figure 13.15

What will be displayed?


c A customer wants to know the possible combinations for a car with leather seats
and either silver or grey paint.
What search condition needs to be input? Copy and complete the table.

261
Figure 13.16

3 A database was set up to compare oil companies. A section of the database is


shown below:

Figure 13.17

a How many fields are there in each record?


[1]
b The following search condition was entered:
(No of countries < 30) AND (Head office = “Americas”)
Using Code only, which records would be output?
[2]
c What search condition is needed to find out which oil companies have a share
price less than $50 or whose profits were greater than 8 billion dollars?
[2]
Cambridge IGCSE Computer Studies 7010/0420 Paper 13 Q12 June 2013
4 A database was set up to keep track of goods in a shop. A section of the database is
shown below:

262
Figure 13.18

a How many records are shown in this section of database?


[1]
b i Using Item code only, what would be output if the following search was
carried out?
(Number in stock < Re-order level) AND (Items ordered = “No”)
[2]
ii What useful information does this search produce?
[1]
c Write a search condition to locate items costing more than $2.00 or which have a
stock value exceeding $300.00.
[2]
Cambridge IGCSE Computer Studies 7010/0420 Paper 13 Q9 November 2013

263

You might also like