You are on page 1of 17

IGCSE Computer Science 0984

Chapter 09
Databases

Steal This CS Notes


WHAT THEY WON’T TELL YOU ABOUT CS

Created by:
Mr. Mahmoud Moussa
01098569912
www.mahmoudmoussa.com
Types of Data
The main types of data found in a computer system are:

Alphanumeric/Text A number of characters


Character A single character

Integer Whole number

Real A decimal number

Date / Time Date and/or time


One of two values: either True
Boolean or False, 1 or 0, Yes or No
Types of Data
Why does the computer need to know if the number is integer or real?
Because real numbers take up more storage space.

If a database file has a million records, this can


represent a lot of wasted space.

Why telephone Numbers are not numeric?


May contain additional character(s) such as dash/space/brackets/plus
symbol

Retains leading zeros

Field would not be used for any calculations

4
Example
Data is to be stored in a database and to do this a data type must be chosen for each
item of data. Choose a suitable data type from the following list for the data shown in
the table:
Boolean Alphanumeric/text Character
Integer Date Real

Name of field Example data Data type


Email ict@cie.org.uk Alphanumeric
Phone number 0798273232 Alphanumeric
Gender M or F Character
Country Egypt Text
Date of birth 01/10/03 Date
Years at 4 Integer
address
Price £5.75 Real 5
Database Structure
Database Definition
Database - An organized sets of data on a computer.

Databases consist of the following:


Files File

Records
Fields Record 1 Record 2 Record 3

F F F F F F F F F

Structure of a database
Note:
Data is often stored in files, which consist of records,
which in turn consist of fields. 6
Example of a Database
Our school holds lots of information about students on its database.
Lets take a look at the data we might hold.

Cand No.: 8209 Cand No.: 8211 Cand No.: 8215 Cand No.: 8220
Name: Heba Name: Ahmed Name: Roaa Name: Abbas
D.O.B: 3 Mar 1995 D.O.B: 3 Apr 1995 D.O.B: 3Jun1995 D.O.B: 3Aug1995
Phone: 3916203 Phone: 3716206 Phone: 3816209 Phone: 3516207
Grade: 10 PC Grade: 10 QE Grade: 10 PC Grade: 10 QE

Notice how each student has similar information stored about them. For example,
Name and D.o.B. We want to store this information in an organised way so that we can
access it easily. In other words we want a database. 7
Database Records & Fields
What is a Record?
The information about an item or person.
Example:

Cand No.: 8209 Cand No.: 8211 Cand No.: 8215 Cand No.: 8220
Record 1

Record 2

Record 3

Record 4
Name: Heba Name: Ahmed Name: Roaa Name: Abbas
D.O.B: 3 Mar 1995 D.O.B: 3 Apr 1995 D.O.B: 3Jun1995 D.O.B: 3Aug1995
Phone: 3916203 Phone: 3716206 Phone: 3816209 Phone: 3516207
Grade: 10 PC Grade: 10 QE Grade: 10 PC Grade: 10 QE

What is a Field?
A field is a single item of data.
Field 1
Example: Cand No.: 8209 Field 2
Name: Heba
Our records contain 5 fields. D.O.B: 3 Mar 1995 Field 3
Phone: 3916203
Grade: 10 PC Field 4
8
Field 5
Database Files
What is a Database File?
A file is a collection of related records.

The contents of database files are often viewed as Tables.


Database Tables allow you to see the records all at once rather than individually.

Our student database would look like this when viewed as a table:

CandNo Name DOB Phone Grade


8209 Heba 3 Mar 1995 3916203 10 PC
8211 Ahmed 3 Apr 1995 3716206 10 QE
8215 Roaa 3Jun1995 3816209 10 PC
8220 Abbas 3Aug1995 3516207 10 QE

9
Database Files
CandNo Name DOB Phone Grade
8209 Heba 3 Mar 1995 3916203 10 PC
Each row
8211 Ahmed 3 Apr 1995 3716206 10 QE in a table
8215 Roaa 3Jun1995 3816209 10 PC contains a
8220 Abbas 3Aug1995 3516207 10 QE
record.

Each
CandNo Name DOB Phone Grade column in
8209 Heba 3 Mar 1995 3916203 10 PC a table
represents
8211 Ahmed 3 Apr 1995 3716206 10 QE
a field.
8215 Roaa 3Jun1995 3816209 10 PC
8220 Abbas 3Aug1995 3516207 10 QE

Data in the Field Field Name


Q: How many records and fields are there in the student file?
10
A: 4 records and 5 fields.
Primary Key (Key field)
Every record in a database needs to be uniquely identified.

Unique data makes sure that when we are accessing a record, we are accessing
the right one
Take another look at our student database. Which item of data uniquely
identifies students from each other?

CandNo Name DOB Grade


8209 Heba 3 Mar 1995 10 PC
8211 Ahmed 3 Apr 1995 10 QE
8215 Roaa 3Jun1995 10 PC
8220 Abbas 3Aug1995 10 QE

Name Cand No
A key field is a piece of data in a database
D.O.B Grade that is unique to a particular record. 11
Example
Pupil records are kept on a computer in the school office. Here is a part of a file
of year 12 student records.

ExamNumber PupilName Gender Form HomePhone DateOfBirth


1001 Zhang Zhiyaq M MJ 3574891 08/06/1995
1002 Kumar Mohandas M NK 6542738 07/01/1995
1003 Mohammed Hafiz M NK 6541984 01/01/1995
1004 Janine Dixon F KL 4256234 02/12/1995

Write down the name of the field which would be used as the key field. [1]
ExamNumber
Why would it be used? [1]
Because it is unique for each candidate.
Why is it more suitable to use date of birth rather than age? [1]
Age for each student changes every year and so database file will need to be
continually updated. 12
Validation
Validation

Validation is a process where data is checked to see if it


satisfies certain criteria when input into a computer
For example to see if the data falls within accepted
boundaries.

Examples of validation checks:

Range Check
Checks whether data is within given values.
e.g: age > 0 and < 120
Length Check
Checks if the input data contains the required number of characters.
e.g: if field needs 6 digits, inputting 5 or 7 causes error message.
Validation
Examples of validation checks:

Format/ Picture Check


Checks that data is in a specific format.
e.g: dd/mm/yyyy

Type Check

Checks that the input data does not contain invalid characters.

e.g: person’s name should not contain any numbers


Validation
Examples of validation checks:

Presence Check
Checks if data is actually present and has not been missed out.
e.g: if no data is present, this should give an error message
Consistency Check
Checks if fields correspond with each other.
e.g: if Mr is typed, then gender must be Male.
Error Checking Methods
Examples of validation checks:

Check digit

How check digit is created?

A digit that is calculated from the data

It is appended to the data

How a check digit can be used to make sure the data entered is correct?

Data is input with check digit


A calculation is performed on the inputted data
The calculated digit is compared to a stored value
If it matches, the data entered is correct
If it does not match, the data entered is incorrect
16
Error Checking Methods
Examples of when a check digit is used

International standard book numbers (ISBN)

Bar codes

Types of data entry errors that a check digit would detect


Two digits transposed
Example: 280419 becomes 280149 (two digits have been switched)
Incorrect digit

Example: 280419 becomes 250419 (one of the digits has been mistyped)

17
Verification
Verification

Verification means to check that the data on the original source


document is identical to the data that you have entered into the
system or object document.

There are two ways that verification checks are carried out:
Double Data Entry

Data is typed in twice by one typist or data is typed in by two operators and
computer compares versions
If different freezes/sounds buzzer.

Visual check

This is the checking for errors by comparing entered data on the screen
with the data in the original document

You might also like