Databases - 085241
Databases - 085241
Chapter 5
Database
Introduction
A data base is a collection of data stored
in a computer system in some organised
manner to make the retrieval of the data
easy.
1
14/07/2023
Database concepts 1
Traditionally filling methods
Thisis the old way of organising files. This
method is where data is stored within a single
paper file or table.
Database concept 2
Computerised database
This database use database management
system software to manipulate data.
Examples of DataBase Management
Software (DBMS) include:
MS-Access
Oracle
Fox Pro
Dbase IV
2
14/07/2023
Functions of DBMS
Allow the user add or delete records.
Update or modify existing records.
Organise data for easy access, retrieval
and manipulation.
Ensure security for data in the database.
Keeps statistic of data items in database.
3
14/07/2023
Database models 1
Flat files – this model of
database holds only one
set of data and is not any
different from the manual
files e.g. the library
catalogue.
Hierarchical model – in
this model items are
arranged in hierarchical
(tree) form. To access
level one data items, you
have to first access level
one data items. A specific
single path leads to each
item at lower levels.
7
Database models 2
Network model – in this model,
lines are used to express the
relationship between different
data items, forming a network
of items. Access of one item
can be through many paths
and from any item.
Relational model – in this
model, related data items are
stored together in structures
called relations or tables.
Relationship can be created
between tables such that a
record or records from one
table relates to another in
another table.
8
4
14/07/2023
Database models 3
Object oriented model – in this model,
database is a complete program built to
hold a collection of objects, which have
both properties and behaviour.
Features of database 1
Tables/file structure –
this is database
structure that is used
to hold related
records.
Queries – this is a
tool used to search
for or question a
database on specific
records.
10
5
14/07/2023
Features of database 2
Form/Screen input – this
is a graphical interface
that resembles the
ordinary paper form used
to collect data. It enables
the user to view and enter
data into a table.
Report – database
provides the user with a
tool for generating reports
from a table or query.
11
Features of database 3
Modules – this tool is like the macro but
it’s more precise in the sense that you
have control over the actions taken.
6
14/07/2023
7
14/07/2023
2. Click “Exit.
8
14/07/2023
9
14/07/2023
10
14/07/2023
11
14/07/2023
Field properties 1
Field size – allow the user to set the number
of characters in a field instead of the default
50 for text fields. For numeric fields integer,
bytes, single, double or long integer is used.
12
14/07/2023
Field properties 2
Decimal places – for number or currency
fields you can specify the number of
decimal place.
Field properties 3
Caption – it’s a more descriptive name for
a field to be used in a table or a form
display e.g. a caption Fname could be
First name.
13
14/07/2023
Field properties 4
Validation rule – it’s a logical expression
that restricts values to be entered in a field
e.g. to restrict value entered in a field to be
between 0 and 100 type > = 0 and < = 100.
Field properties 5
Required – Determines if an entry must be
made in the field before you proceed to
the next field or record.
28
14
14/07/2023
Field properties 6
Indexed – it facilitates the organisation of
records for easy search.
15
14/07/2023
16
14/07/2023
2. On the “Insert”
menu.
17
14/07/2023
3. Click “Delete”.
18
14/07/2023
19
14/07/2023
20
14/07/2023
21
14/07/2023
22
14/07/2023
23
14/07/2023
24
14/07/2023
Importing tables
You can import a table from another
database or a spreadsheet into your
database.
25
14/07/2023
Form designs
A form is an interface that
enables the user to view and
make data entries into an
underlying table more easily.
A form is designed using
graphical objects called
controls.
A control is an object
such as textbox,
checkbox, command
button or shapes placed
on form design grid to
display data or perform
actions. 51
Types of controls
Bound – in this the source of data is a field
in a table or query.
52
26
14/07/2023
Form designer
You design or modify
a form layout by
dragging these
controls to the
required position.
Figure right shows a
form designer for a
table called exam
entry.
27
14/07/2023
28
14/07/2023
29
14/07/2023
30
14/07/2023
31
14/07/2023
Using queries
Queries are the fastest way to search for
information in a database. It also enables
the user display specific records and also
perform calculations on field from tables.
64
32
14/07/2023
Types of queries
Select query – most commonly used, it is
used for searching and analysing data in
one or more tables. It lets the user specify
the search criteria.
65
66
33
14/07/2023
7. Select “Detail” or
“Summary”.
34
14/07/2023
35
14/07/2023
36
14/07/2023
37
14/07/2023
38
14/07/2023
2. Select “ascending”
or “descending”.
39
14/07/2023
40
14/07/2023
41
14/07/2023
42
14/07/2023
Relationship in tables
Entity – an entity is a thing or object of
significance, whether real or imagined,
about which information needs to be
known or held.
Attribute – an attribute is any detail that
serves to qualify, identify, classify, quantify
or express the state of an entity.
Candidate key – it’s any attribute or set of
attributes can be used to uniquely identify
a row in a table. 86
43
14/07/2023
Types of relationships
One-to-one relationship – for a particular
field in one table there is only one
matching record in the related table.
One-to-many relationship – for a particular
field in one table there are several
matching records in another table.
Many-to-many relationship – for particular
records in one table there are several
matching records in the other table. 87
44
14/07/2023
45
14/07/2023
Creating reports
Like in forms, a report
layout is also
designed by placing
controls on to the
report designer as
shown in figure right.
Parts of a report
Report header – this contains unbound controls that displays
title of the report.
Page header – contains heading or labels data items to be
displayed in every column.
Detail – holds bound controls that display data items for the
table or query it was created from.
Detail – holds bound controls that display data items for the
table or query it was created from.
Page footer – holds a control that is to be displayed on every
page such as the page number and date. For example =Now()
displays the current date and time as set in the system clock.
Report footer – used to display summary from a report such as
the grand total for numerical data in a particular field column.
46
14/07/2023
Creating a report
Using wizard
Just like the form wizard, report wizard takes
the user through a number of steps by
answering a few questions and MS-Access
automatically does the rest.
In design view
Justlike with forms, you can create a report in
design view by placing control on the report
design grid.
3. Select “Report
Wizard”.
47
14/07/2023
48
14/07/2023
49
14/07/2023
50
14/07/2023
51
14/07/2023
Creating labels
A label is a sticker or piece of paper put on
an item for the purpose of identification.
Examples of stickers are mailing labels,
label on the floppy disk where you write
your name etc. Using the report label
wizard, MS-Access lets you easily create
labels of different sizes.
52
14/07/2023
53
14/07/2023
Modifying labels
Just as you can modify a report or a form,
you can also modify a label by
manipulating the layout controls
54
14/07/2023
55
14/07/2023
Creating macros
A macro is a set of one or more actions
used to automatically perform particular
operations such as opening a form or
printing and a report. Macros are used to
automate database applications.
56
14/07/2023
57
14/07/2023
1. Open MS-Access.
2. On the “File” menu.
3. Click “Open” (Open dialog
box is displayed).
4. Click arrow down sign of
“Open” button. (open menu
is displayed).
5. Open the database in
exclusive mode which you
want to set a password.
(Security Warning dialog box
is displayed).
6. Click “Open” button.
58
14/07/2023
59
14/07/2023
60
14/07/2023
61
14/07/2023
62
14/07/2023
63
14/07/2023
1. On the “Tools”
menu.
2. Click “Startup”.
(Startup dialog box
is displayed).
3. Set startup options
e.g. “Application
Title”, “Application
Icon” or etc.
4. Click “OK” button.
Review questions 1
1. What is a relational database
management system?
2. Define the following terms: table, records
and field as used in databases.
3. State six major objects used to
manipulate data in MS-Access.
4. Explain how you can start and exit MS-
Access.
5. In MS-Access, what do the following
terms refer to: query, macro, module. 128
64
14/07/2023
Review questions 2
1. Differentiate between a primary key and an
index.
2. What is normalization in reference to tables?
3. Describe various data types used in MS-
Access.
4. Explain how you would set a validation rule
when designing tables.
5. What are field properties?
6. What is the difference between a field name
and a caption? 130
65
14/07/2023
Review questions 3
1. Define the following terms:
A) Form;
B) Bound and unbound control;
2. Differentiate between tabular and columnar form layout.
3. Explain how you would create a form without using a
form wizard.
4. Why would one prefer to use a form for data input rather
than entering directly into a table?
5. Explain how you would move from one record to
another in a form.
6. Draw a simple sketch of a form that can be used to
enter all subjects marks in an examination database.
132
66
14/07/2023
133
Review questions 4
1. Explain two tools you can use to search for data in a database.
2. What is Referential Integrity?
3. Differentiate between a table and a query.
4. Write down the criteria you would use to display employees’
details from a payroll database who earn between 90,000 and
240,000.
5. Explain how you would sort data in a query.
6. What is the difference between an action query and a select
query?
7. Explain what happens when you try to enter invalid data into a
related table for which referential integrity has been reinforced.
8. Explain how you would create a select query that would be
134
used to calculate your total score and average in ten subjects.
67
14/07/2023
135
Revision questions
1. What is the importance of a report generated from a
database?
2. What is the difference between a report and a label?
3. Explain how you would create a report that displays
subtotals and grand totals.
4. Dr. Garaya is a pharmacist. She wants to generate
labels that she can use to stick to medicine bottles.
Explain to her how she can generate labels of different
sizes using MS-Access database.
5. Assuming you have been appointed as the sales
representative of an insurance company, explain how
you would create annual reports that would include the
company logo at the top of every page. 136
68
14/07/2023
Practical activity 1
Create a database
Field Name Data Type called Employees and
ID Number Text in it create a table
Last name Text
called customers with
the right fields:
First name Text
a. Save the Table as
Address Text CUSTOMER.
Town Text b. In the description
column, which is
Company Text
optional, describe what
Date Dates/Time each field is for, e.g. ID
Salary Currency Number is the number
that identifies each
Married? Yes/No employee uniquely.138
69
14/07/2023
Practical activity 2
A) In the database, create
a table called DVDs
with the right attributes:
B) Determine the following
in A above.
i. The primary key;
ii. The missing data types
and properties;
iii. Field captions.
70
14/07/2023
71
14/07/2023
143
144
72
14/07/2023
145
146
73
14/07/2023
Practical activity 5
1. Open the Riceland database and generate a report that
displays the following:
1. Employee name, the gross salary, allowances and the net pay.
2. Subtotals and grand totals for all the employees.
3. The current date and time.
2. You have been requested by the School Principal to create a
school database that includes the following:
1. Four departments (Maths, Science, Humanities and Technical subjects);
2. Members of staff in each department;
3. Subjects offered in a department.
1. From the database, generate a grouped report for all members of
staff in each department.
2. Create labels to be placed at the door of every head of department’s
office. 147
74