0% found this document useful (0 votes)
10 views74 pages

Databases - 085241

Uploaded by

theeeclipse17
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)
10 views74 pages

Databases - 085241

Uploaded by

theeeclipse17
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/ 74

14/07/2023

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

Disadvantages of traditional methods

 Unnecessary duplication of data.

 Boredom and time wasting while


searching for a record.

 Misleading reports due to poor data entry.

 Poor update of records. 5

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.

 Macro – this tool enables the user to


automate frequently performed procedures
or tasks.

6
14/07/2023

Data organisation in a database


 Field – this is a character or a logical
combination of characters that represent a
data item e.g. in a class list the Admno is a
field.
 Records – this is a collection of related fields
that represents a single entity e.g. student
name, sex, age, marks etc.
 File – this is a collection of related records.
 Database – this holds all related files or
tables. 13

Creating a database using MS-Access


1. Click “Start”.
2. Point to “Programs/All Programs”.
3. Point to “Microsoft Office”.
4. Click “Access 2003” (application is
opened).
5. On the task pane, click down arrow
sign of click “Getting Started”
(shortcut menu is displayed).
6. Select “New file”.
7. Click “Blank database” (File New
Database dialog box is displayed).
8. Select the location where you want
to create the database from the
arrow down list.
9. Type the name of database in the
file name box.
10. Click “Create” button.

7
14/07/2023

Microsoft Access screen layout

Steps of “exiting from Access”


1. On the “File” menu.

2. Click “Exit.

NB: shortcut key


Alt+F4

8
14/07/2023

Steps of “creating a table structure” 1

1. Click “Table” tab.


2. Click “New”. (New
Table dialog box is
displayed).
3. Select “Design View”
from the list.
4. Click “OK” button.
(Table is displayed).

Steps of “creating a table structure” 2

5. Type a unique name


for each field in the
table.

6. Select “Data Type”


from the down arrow
list.

7. Add the other fields.

9
14/07/2023

Steps of “creating a table structure” 3


8. After you add in other
fields, click “Save”
button on the standard
toolbar. (Save As dialog
box is displayed).
9. Type the name of table
in the “Table Name”
box.
10. Click “OK” button.
(Message box is
displayed).
11. Access will ask you
whether you want to
create a “Primary Key”,
click “Yes”.

Rules of a filed name in the table

 A field name must start with a letter and


can be up to a maximum of 64 characters
including letters, numbers, spaces and
punctuation.

10
14/07/2023

Field data types 1


 Text – it includes alphabetic letters, numbers,
spaces, punctuation etc. This data type is used
in field that needs no calculations.
 Number – this field is made up of numeric
numbers 0-9 that are to be manipulated
mathematically.
 Memo – this is made up of alphanumeric data
used if you need to enter several paragraphs of
text.
 Data/Time – identify a field either as date or time.
21

Field data types 2


 Currency – identify a numeric value that have
decimals or fractions used when dealing with
monetary values.
 Autonumber – it’s a numeric value used if you
want MS-Access to automatically increment the
values in the field.
 Yes/No – it’s a logical field where an entry is
either a “Yes” or “No” “True” or “False”. Ole
object – this data type is used with graphical
user interface application for inserting graphical
objects.
22

11
14/07/2023

Field properties settings


 As you create more and
more complex tables, you
will find a need to use field
properties to specify finer
details related to fields and
table entries expected. Field
properties depend on the
type of field selected. For
example, when you click on
a “Text” field, then the
“General” tab, you will see
properties associated to text
data type as shown in figure
right.

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.

 Format – determines how information


appears on the screen and when printed e.g.
you can format number to scientific,
currency, % etc 24

12
14/07/2023

Field properties 2
 Decimal places – for number or currency
fields you can specify the number of
decimal place.

 Input mask – it automatically formats the


field entry into specified format e.g. a
number 02042426090 and the input mask
is set as 000-(0000)-(0000) it will
automatically display as 020-4242-6090. 25

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.

 Default value – this is a value that will


appear automatically in the form if nothing
is entered by the user to change it e.g.
Date () automatically displays current date. 26

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.

 Validation text – this is message that


appears once the validation rule is violated
e.g. you may enter a validation rule for the
above rule to display “Enter a number
between 1 and 100” 27

Field properties 5
 Required – Determines if an entry must be
made in the field before you proceed to
the next field or record.

 Allow zero length – allows the user to


proceed without making any entry in the
field set as zero length.

28

14
14/07/2023

Field properties 6
 Indexed – it facilitates the organisation of
records for easy search.

 Primary key – it’s a field that enforces


uniqueness in a table so that one record is
not entered twice.

 Index – this is a feature used to speed up


search and sort operations in a table.
29

Primary key and indexes.


 An index is a key(s) used to speed up searching
and sorting records in a table, while a primary
key is an index that uniquely identifies each
record stored in the table. A primary key
prevents the user from making null or double
entries into a table. Access uses the primary key
to order records, and control redundancy. Once
a field is set as primary key, the datasheet in
automatically indexed or sorted using the
primary key.

15
14/07/2023

Steps of “set a primary key”


1. Open the table in
design view.
2. Select the field you
want to set as the
primary key by
clicking in the row
header to the left the
“Field Name”.
3. Click “Set Primary
Key” button on the
tools bar.

Steps of “set another field as an


index other than the primary key”
1. Open the table in design view.
2. Click “Indexes” button next to
the primary key. (Indexes
dialog box is displayed on the
screen as shown in figure right
above.
3. In the “Index Name” column,
type the name of the index.
4. In the “Filed Name” column,
select the corresponding
fieldname.
5. In the “Sort Order” column,
select “Ascending” or
“Descending”.
6. “Close” dialog box.

16
14/07/2023

Steps of “adding new records”


1. Double click the
table icon. (the table
is displayed in
datasheet view”.

2. On the “Insert”
menu.

3. Click “New Record”.

Symbols of row header.


 An arrowhead indicates
that no new data entry or
edit is pending.
 Asterisk symbol marks a
blank record below the
current entry.
 Pencil symbol indicates
that the current record
entry is not yet saved.
 Record locked indicates
that the current record is
being edited by another
user in a multi-user or
networked environment.

17
14/07/2023

Steps of “deleting records”


1. Click the record you
want to delete.

2. On the “Edit” menu.

3. Click “Delete”.

Steps of “editing fields”


1. Double click the field
you want to edit.

2. Replace the cell


content.

18
14/07/2023

Steps of “searching for records”


1. On the “Edit” menu.
2. Click “Find”.
3. In the “Find What” box,
type the field to search.
4. Select other options for
find “Look In”, Match or
etc.
5. Click “Find Next” button.

NB; shortcut key


Ctrl + F

Steps of “Replace a records”


1. On the “Edit” menu.
2. Click “Replace” (Find and
Replace dialog box is
displayed).
3. In the “Find What” box, type
the name of field to replace.
4. In the “Replace with” box,
type field to replace with
respectively.
5. Select other options for find
“Look In”, Match or etc.
6. Click “Replace” or “Replace
All” button.

19
14/07/2023

Steps of “copying records”


1. Select the record(s) to
be copied.
2. On the “Edit” menu.
3. Click “Copy”.
4. Select the target
datasheet to copy.
5. On the “Edit” menu.
6. Click “Paste”.

NB: shortcut key for “Copy”


Ctrl + C
shortcut key for “Paste”
Ctrl + V

Steps of “moving records”


1. Select the record(s) to
be moved.
2. Click “Cut command on
the standard toolbar.
3. Select the target
datasheet to move.
4. Click “Paste” command
on the standard toolbar.

NB; shortcut key for move.


Ctrl + X

20
14/07/2023

Steps of “Sorting records”


1. Open the table in
datasheet view.
2. Select the records to
be sorted.
3. On the “Record”
menu.
4. Point to “Sort”.
5. Click “Ascending” or
“Descending”.

Steps of “Filtering records”


1. Open the table in
datasheet view.
2. Select the records to be
filtered.
3. On the “Record” menu.
4. Point to “Filter”.
5. Select the type of filter
you want to apply.
6. In the datasheet, click a
down arrow of the field
to set the filter option.
7. Click “Apply Filter”
button on the toolbar.

21
14/07/2023

Steps of “adjust the column size”

1. Point to the column


border between the
field’s header.
(mouse pointer sign
will be changed to
black cross sign).
2. Change the column
size up to where you
require using drag
and drop.

Steps of “adjust the row height”


1. Point to the border between
two rows in the row header.
(mouse pointer sign will be
changed to black cross
sign).
2. On the “Format” menu.
3. Click “Row height”. (Row
Height dialog box is
displayed).
4. Delete current row height
and type the new row height
which you want to adjust.
5. Click “OK” button.

22
14/07/2023

Steps of “reorder fields”


1. Select the column of
the field you wish to
move by pointing to
the desired file
name.
2. Drag the column
right or left to the top
of the field where
you want your field
to appear and then
drop.

Modifying table structure


 Once you create a table, you may need to add
more fields, remove some fields, reorder the
fields or change fields data types and properties.
Before you modify the table it is important to
save a copy to avoid losing everything in case
you make a mistake.
 If a table contains data and you make changes
to the field data type, MS-Access may refuse to
implement the changes. To avoid this problem,
exit without saving and delete all the records
from the table then return to the design view.
You can then import a copy or copies of tables
you backed up.

23
14/07/2023

Steps of “make a copy of your table”


1. On the “File” menu.
2. Click “Save As/Export.
(dialog box is
displayed).
3. Choose whether to
save to another
(external) database or
the current database.
4. Type a new name for
your table.
5. Click “OK” button.

Steps of “modify the original table”

1. Open the table in


design view.
2. Select the field or
fields to be modified
and make the
necessary changes.
3. Click the “Save”
button to save the
changes.

24
14/07/2023

Importing tables
 You can import a table from another
database or a spreadsheet into your
database.

Steps of “import a table or a worksheet”


1. On the “File” menu.
2. Point to “Get External Data”.
3. Click “Import”. (Import dialog
box is displayed).
4. Select the database you
wish to import data from.
5. Click “Import” button.
(Object dialog box is
displayed as shown in figure
below).
6. Click “Table” tab.
7. Select the table(s) you wish
to import.
8. Click “OK” button.

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.

 Unbound – this control is not connected to


any data source.

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.

Creating a form layout using form wizard

 To create a form layout, you can either use the form


wizard or start from scratch. Using the form wizard you
can create either a columnar, a tabular a datasheet or
a justified form layout.
 Columnar form: the fields for each record are displayed
down a column i.e. each value displays on a separate line
with field labels to the left.
 Tabular: records are displayed from left to right across the
page and labels appear at the top of each column. Each row
represents a new record.
 Datasheet: the form resembles a table datasheet view.
 Justified: one record occupies the whole form.

27
14/07/2023

Steps of “create a form using the wizard” 1

1. Click “Form” tab.


2. Click “New”. (New Form
dialog box is displayed).
3. Select “Form Wizard”.
4. Select the name of the
table or query that
includes the data you
want to add into the
form from down arrow
list.
5. Click “OK” button.

Steps of “crating a form layout using form wizard” 2.

6. Select the fields to


add into the form by
clicking the “>”
button or click “>>”
to add all fields.
7. Click “Next” button.
8. Select the layout you
wish to use
“Columnar”, Tabular”
or etc.
9. Click “Next” button.

28
14/07/2023

Steps of “crating a form layout using form wizard” 3

10. Select the style you


wish to use “Blends”,
“Blueprint” or etc.
11. Click “Next” button.
12. Type the name of the
form title in the box.
13. Click “Finish” button.
(MS-Access will
automatically display
the form on the screen).

Creating a form using autoform wizard

 You can easily create a form using the


“Autoform wizard”. This wizard creates a
form for you automatically by asking you
very minimal questions. The form includes
all the fields from the selected table.

29
14/07/2023

Steps of “construct an autoform”


1. Click “Form” tab.
2. Click “New”. “New Form
dialog box is displayed).
3. Select autoform layout
“Columnar”, “Tabular” or etc.
4. In “Choose the table or query
where the object data
comes”, select the table or
query form from down arrow
list you wish to create a form
for.
5. Click “OK” button.
6. Click “Save” button on the
toolbar. (Save As dialog box
is displayed).
7. Type the name of the form.
8. Click “OK” button.

Steps of “creating a form from scratch”


1. Click “From” tab.
2. Click “New”. (New Form dialog
box is displayed).
3. Select the “Design view” from the
list.
4. In “Choose the table or query
where the object data comes”,
select the table or query form
from down arrow list you wish to
create a form for.
5. Click “OK” button. (a form with
controls for all fields is
displayed).
6. Arrange the form as you want.

30
14/07/2023

Steps of “add controls onto a form”


1. On the “View” menu.
2. Click “Field list”. (the
field of the table you
selected is
displayed).
3. Drag and drop each
field and arrange
them on the grid.
4. Click “Save”
command on the
toolbar.

Adding and displaying records


 The form provides the user
with navigation buttons
located at the bottom that
can be used to navigate the
form as shown in figure
below. The functions of the
buttons can be summarized
from left to right as follows:
1. Displays the first record in the
table.
2. Displays the previous record.
3. Displays the next record.
4. Displays the last record.
5. Used to add a new record.

31
14/07/2023

Steps of “format controls on a form” (resize)

1. Open the form in design


view.
2. Select the field which you
want to resize. (place
holders are displayed
around field).
3. Place the mouse pointer on
the place holder. (mouse
pointer sign will be changed
to a double-sided arrow
sign).
4. Resize using drag and
drop.

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.

 Action query – these are used to make


changes to many records once.

65

Types of action queries


 Update – updates data in table.
 Append query – adds data in a table from
one or more tables.
 Make table query – creates a new table
from a dynast.
 Delete query – deletes specified records
from one or more tables.

66

33
14/07/2023

Steps of “creating a select query using wizard” 1

1. Click “Queries” tab.


2. Click “New”. (New query
dialog box is displayed).
3. Click “Simple Query Wizard”.
4. Click “OK” button.
5. Select the name of the table
or query that includes the
data you want to add into the
query from down arrow list.
6. Select the fields to add into
the query by clicking the “>”
button or click “>>” to add all
fields.
7. Click “Next” button.

Steps of “creating a select query wizard 2”

7. Select “Detail” or
“Summary”.

8. Click “Next” button.

9. Type the title name of


query in the box.

10. Click “Finish” button.

34
14/07/2023

Steps of “creating a select query from in design view” 1

1. Click “Queries” tab.


2. Click “New”. (New query
dialog box is displayed).
3. Select “Design View”.
4. Click “OK” button. (Show
Table dialog box is
displayed).
5. Select table, query or both
which you want to add into
the query from each tab.
6. Click “Add” button.
7. After you add, click “Close”
button.

Steps of “creating a select query from in design view” 2

 The query design grid


opens. In MS-Access
it is called “Query-By-
Example” (QBE). This
lets the user to design
a query. Figure right
is QBE grid for a table
called Exam.

35
14/07/2023

Parts of the query grid


 Field row – fields from a table or tables to be used are
arranged in this row. Each field should occupy its column.
 Table row – indicates the table providing the fields.
 Sort row – by clicking the down arrow in the sort cell, you
can specify the sort order i.e. ascending, descending or not
sort.
 Show row – by clicking the Show box, you specify whether
to display the field in the query results. When the box is not
checked, the field will not be displayed.
 Criteria row – this is where you type conditional statement
that will be used by the query to display specific records.
 Or row – used to specify an alternative condition e.g. if you
want to display records with a field called City, with items
Nairobi or Embu, type Nairobi in criteria cell and Embu in
the Or cell.

Specifying the criteria search


 To search for a particular set of records,
the users have to enter a conditional
statement in the criteria row. For example
if you have a table called employees with
one of the fields as salary, you can display
all the employees earning more than Shs.
5,000 by typing>5000 in the criteria row,
salary column.
72

36
14/07/2023

Other examples of specifying the criteria search 1

 To define criteria, use either relational or logical


operators. Relational operators include less than (<),
greater than (>), greater than or equal to (>=), less
than or equal to (<=), not equal to (<>) and equal to
(=). Logical operators include AND, OR and NOT.
 Use AND to display values in a specific range. For
example, to display records from the employees table
with salaries above 4000 but less than 6000, type,
>4000 AND <6000 on the criteria row in the salary
column. All the employees who meet this condition will
be displayed.
 Use OR if you wish to get either one of two values. For
example, if you wish to get those employees either in
Nairobi OR Embu.

Other examples of specifying the criteria search 2

 If you want to display data in a particular range, use the


word Between. For example, instead of typing, >4000 AND
<6000, type Between 4000 And 6000.
 If you want to list all records except those that you do not
want to see, use NOT. For example, if you type NOT 6000
in the salary column of the employees table, all employees
records will be displayed except those with their salary as
6000.
 To display records you are not sure of the field name but at
least you can remember a few characters, use LIKE and the
wildcards. Wildcards are special symbols mostly an asterisk
and a question mark used in place of other characters. For
example, to display all names starting with “Sm” followed by
any other character, type Like Sm? Like */*/1993 lists
records created in 1993 regardless of the day or month.

37
14/07/2023

Steps of “add fields into the query grid”

1. Open the query in


design view.

2. From the field list of


the underlying table,
drag each field and
place it in the field
row.

Steps of “saving the query”


1. Click “Save” button
on the toolbar or
from the “File” menu.
(Save As dialog box
is displayed).

2. Type name of the


query in the box.

3. Click “OK” button.

38
14/07/2023

Steps of “running the query”


 Click “Run” button on the
toolbar as shown in figure
right above or “Run”
command from the “Query”
menu. (results of the query
is displayed).

NB: you can also view the


results of your query any
other time by selecting the
query, then click “Open”
button from the database
window.

Steps of “sorting the dynaset”


1. Click the down arrow
button of the “Sort”.
(list is displayed).

2. Select “ascending”
or “descending”.

39
14/07/2023

Steps of “delete fields from the query grid”

1. Open the query in


design view.
2. Select the field column
you wish to delete.
3. On the “Edit” menu.
4. Click “Delete”.
5. After you delete, click
“Save” command on
the toolbar to save the
changes.

Steps of “adjust the column size in a query”

1. Open the query in design


view.
2. Position the mouse pointer
at the boundary that
separates columns. (mouse
pointer sign will be changed
block cross sign).
3. Double click on the
boundary to autofit cell
content.
4. Click “Save” command on
the toolbar to save the
changes.

40
14/07/2023

Steps of “modify a criteria statement, select query”

1. Open the query in


design view.
2. Select the field of criteria
which you want to
modify, then change the
criteria statement as you
desire.
3. Click “Save” command
on the toolbar to save
changes.
4. Click “Run” command to
display the results of the
query for test whether
the changes have been
effected.

Performing calculations in a query.

 Unlike tables, queries let the user perform


mathematical calculations on numeric data.
You can perform calculations in a query by;
A) Creating basic formulae – to create a formula
that calculates the total marks in an underlying
table e.g. Exams table.
B) Using Total functions – with a query, you can
analyze all record fields using the inbuilt
functions such as Sum, Average, Minimum and
Maximum etc.

41
14/07/2023

Steps of “creating basic formulae”


1. Open the query in
design view.
2. In an empty cell, type an
expression that includes
a field name of each as
“Amount: [Quantity] *
[Unit Price] as shown in
figure right above.
3. Click “Save” command
on the toolbar.
4. Click “Run” command
on the toolbar. (the
results of the
calculations is
displayed).

Steps of “use the total functions”


1. Open the query in design view.
2. Click “Totals” command on the
tool bar. (Totals row is
displayed which is located
between “Table” row and
“Sort” row).
3. For each field to be analyzed,
click its cell in the “Total” row,
and then select any of the
functions from arrow down list
of “Total” row.
4. Set criteria and other options.
5. Click “Run” command on the
toolbar to preview the results.
6. Click “Save” command to save
the changes.

42
14/07/2023

Steps of “printing a query”


1. Click “Queries” tab.
2. Open the query in
datasheet view you
want to print.
3. On the “File” menu.
4. Click “Print”.
5. Select the printer
from arrow down list.
6. Set the other printing
options.
7. Click “OK” button.

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

Steps of “defining relationship between tables” 1

1. Open the database.


2. On the “Tools” menu.
3. Click “Relationship. (Show
Table dialog box in
Relationship is displayed).
4. Select the table from Table
tab.
5. Click “Add” button.
6. After you add, click “Close”
button.
7. Click the field of first table
which you want to create
relationship.
8. Drag it to the second table
then drop. (Edit Relation ship
dialog box is displayed).

44
14/07/2023

Steps of “defining relationship between tables” 2

7. Make sure “Enforce


Referential Integrity” is
checked to ensure that all
records entered in the
related table exist in the
primary table.
8. Set other options if you
want.
9. Click “Create” button.
(Black line is displayed
between two tables).

NB; the field used to create the


relationship must be of the
same type and properties.

Steps of “create a query based on related tables”

1. Open the query in design view.


2. Click “Show Table” command on
the toolbar. (Show Table dialog
box is displayed).
3. Select the tables you want to
base your query on.
4. Click “Add” button. (query is
displayed).
5. After you add, click “Close”
button.
6. Click the field of first table which
you want to create relationship.
7. Drag it to the second table then
drop. (Edit Relation ship dialog
box is displayed).
8. Click “Run” command to run.
9. Click “Save” command to save.

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.

Steps of “create a report layout using wizard” 1

1. Click “Report” tab.

2. Click “New”. (New


Report dialog box is
displayed).

3. Select “Report
Wizard”.

4. Click “OK” button.

47
14/07/2023

Steps of “create a report layout using wizard” 2

5. Select the name of the table


or query that includes the
data you want to add into the
report from down arrow list.
6. Select the fields to add into
the report by clicking the “>”
button or click “>>” to add all
fields.
7. Click “Next” button.
8. Select the field If you want to
add grouping.
9. Click “>” button to add.
10. Change the priority using
arrow sign button if you want.
11. Click “Next” button.

Steps of “create a report layout using wizard” 3

12. Select the field from


down arrow list if you
want to sort the records.
13. Select “Ascending” or
“Descending”.
14. Click “Summary Options”
button.
15. Click the check box if you
want to perform
calculations on numerical
fields e.g. Sum, Average
or etc.
16. Click “OK” button.
17. Click “Next” button.

48
14/07/2023

Steps of “create a report layout using wizard” 4

18. Select the type of layout


from the list.
19. Select orientation
“Portrait” or
“Landscape”.
20. Click “Next” button.
21. Select the type of style
form the list.
22. Click “Next” button.
23. Type the name of report
title in the box.
24. Click ”Finish” button.

Steps of “creating a report in design view” 1


1. Click “Report” tab.
2. Click “New”. (New Report dialog
box is displayed).
3. Select “Design View”.
4. In “Choose the table or query
where the object data comes”,
select the table or query form
from down arrow list you wish to
create a form for..
5. Click “OK” button. (Report design
grid is displayed).
6. Drag each field from the field list
to the layout grid and drop it
where you want the data column
to appear.
7. After you place, click “Save”
command on the toolbar. (Save
As dialog box is displayed).

49
14/07/2023

Steps of “creating a report in design view” 2

8. Type the name of


the report.

9. Click “OK” button.

10. Click “Print Preview”


button to view the
report.

Steps of “modifying a report layout”


1. Open the report in
design view.
2. Click report header or
footer you want to
modify.
3. Make the necessary
changes.
4. Click “Save” command
on the toolbar to save
the changes.
5. Click “Print Preview”
command on the toolbar
to view the changes.

50
14/07/2023

Steps of “add more controls onto the report layout”

1. Open the report in design


view.
2. Click “Field List” command on
the toolbar. (field list is
displayed).
3. Select one or more fields in
the field list.
4. Add field to design grid using
drag and drop and adjust the
field as you wish.
5. Click “Save” command on the
toolbar to save the changes.
6. Click “Print Preview”
command on the toolbar to
view the changes.

Steps of “resize a control”


1. Click “Report” tab.
2. Open the report in
design view.
3. Select the control you
want to resize. (place
holders are displayed
around control).
4. Place the mouse pointer
on the place holder.
(mouse pointer sign will
be changed to a double-
sided arrow sign).
5. Drag the mouse pointer
to resize the control.

51
14/07/2023

Steps of “move a control”


1. Click “Report” tab.
2. Open the report in
design view.
3. Select the control you
want to resize. (place
holders are displayed
around control).
4. Place the mouse pointer
on the place holder until
its sign is changed to a
hand sign.
5. Drag the mouse pointer
to move the control.

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

Steps of “create a label using the report wizard”

1. Click the “Report” tab.


2. Click “New”. (New Report
dialog box is displayed).
3. Select “Label Wizard” from
the list.
4. In “Choose the table or query
where the object data
comes”, select the table or
query form from down arrow
list you wish to create a form
for.
5. Click “OK” button. (Report
design grid is displayed).
6. Select the size of label you
want to create.
7. Click “Next” button.

Steps of “creating a label using the report wizard” 2

8. Select font type,


size, weight and
color.
9. Click “Next” button.
10. Select mailing labels
from available field
by clicking “>”
button.
11. Click “Next” button.

53
14/07/2023

Steps of “creating a label using the report wizard” 3

12. Sort labels if you


want by clicking “>”
button or click “>>”
button.
13. Click “Next” button.
14. Type the name of
the label in the box.
15. Click “Finish” button.

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

Steps of “modify a label”


1. Click “Report” tab.
2. Click “Design” button. (the
label is displayed in design
view).
3. Edit the layout as desired
4. After you modify, click
“Save” command on the
toolbar.
5. Close the design grid.
6. Click “Print Preview”
command on the toolbar to
view.

Printing the reports and labels


 Before you print a report or a label, you
should first set the page options i.e. the
margins, paper size and orientation.

55
14/07/2023

Steps of “printing the reports and labels”

1. Click “Report” tab.


2. Select the report you want to
print.
3. Click “Preview” button. (Print
Preview window is
displayed).
4. On the “File” menu.
5. Click “Print” (Print dialog box
is displayed).
6. Select the printer from down
arrow list.
7. Set other options i.e. print
range and number of copies.
8. Click “OK” button.

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

Steps of “creating macros” 1


1. Click “Macros” tab.
2. Click “New” button. (Macro window
is displayed).
3. Add an action e.g. OpenTable into
action column from down arrow
list.
4. In the lower part, specify
arguments for the action in Action
Argument box.
5. Type optional comment for the
action if you need.
6. Add more actions to the macro if
you want. Actions are executed in
the order you list them.
7. Click “Save” command on the
toolbar to save the macro.

Steps of “creating macros” 2


8. Type the name of
macro in the box.

9. Click “OK” button.

10. Click “Run”


command on the
toolbar to open the
macro.

57
14/07/2023

Enforcing database security


 MS-Access provides the user with several data security
tools.
A) Password protection – requests the password for opening.
B) Encryption – compacts a database file and makes in
indecipherable by a utility program or a word processor
especially on a networked environment. Encrypting a database
doesn’t restrict access to objects by users.
C) Hiding database object – hide tables, queries, forms and reports
and macros from casual users. This method of protection is the
least secure because it is possible to unhide the objects.
D) User-level security – this is the most extensive security method
especially on a multi-user environment. A database
administrator can grant specific users or groups specific
permissions and privileges to tables, queries, forms. Reports
and macros.

Steps of “setup a password in MS-Access” 1

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

Steps of “setup a password in MS-Access” 2

7. On the “Tool” menu.


8. Point to “Security”.
9. Click “Set Database
Password”. (Set a
Password dialog box is
displayed).
10. Type the unique
password in the box.
11. Re-type the unique
password in the “Verify”
box.
12. Click “OK” button.

Steps of “encrypt a database” 1


1. Start MS-Access without
opening a database
because you can’t
encrypt or decrypt a
database when it is
open.
2. On the “Tools” menu.
3. Point to “Security”.
4. Click “Encode/Decode
Database”
(Encode/Decode
Database dialog box is
displayed).

59
14/07/2023

Steps of “Encrypt a database” 2


5. Select the database you
want to encode or
decode.
6. Click “OK” button.
(Encode Database
dialog box is displayed).
7. Select the location from
down arrow list to save.
8. Type the file name in
the “Name box.
9. Click “OK” button.

Steps of “hide object”


1. On the “View” menu.
2. Click “Properties”.
(Properties dialog
box is displayed).
3. Check in the
“Hidden” box.
4. Click “Apply” button.
5. Click “OK” button.

60
14/07/2023

Steps of “assign user rights and privileges” 1

1. Open the database.


2. On the “Tools” menu.
3. Point to “Security”.
4. Click “User-Level
Security Wizard”.
(Security Wizard
dialog box is
displayed).
5. Click “Next” button.

Steps of “assign user rights and privileges” 2

6. Click “Browse” button.


(Select a workgroup file
dialog box is displayed).
7. Select the location from
shortcut keys.
8. Type the name of file in
the box.
9. Click “Select” button.
10. Type the unique “WID”
(workgroup ID) in the
box.
11. Click “Next” button.

61
14/07/2023

Steps of “assign user rights and privileges” 2

12. Check in the boxes


which you want to select
the database to help
source from each tab.
13. Click “Next” button.
14. Check in the box which
you want to include in
your workgroup
information file.
15. Type “Group ID” in the
box each groups.
16. Click “Next” button.

Steps of “assign user rights and privileges” 3

17. Select “Yes” or “No” to


grant the users group
some permission. If you
select “Yes”, you can set
some option from each
tab.
18. Click “Next” button”.
19. You can add users to
your workgroup
information file. If you
want to add, type “User
name’, “Password” and
‘PID” (personal ID) in
the each box.
20. Click “Next” button.

62
14/07/2023

Steps of “assign user rights and privileges” 3

21. Select “Select a user and


assign the user to groups” or
“Select a group and assign
users to the group”.
22. Click “Next” button.
23. Click “Browse” button.
(Choose a database name
dialog box is displayed).
24. Select the location from
down arrow list to save.
25. Type the “File name” in the
box.
26. Click “Select” button.
27. Click “OK” button.

Setting up startup options


 To customize your database application
workplace, there is need to specify how
the database is to be loaded.

63
14/07/2023

Steps of “set the startup options”

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

Answer of review questions 1


1. A relational database is a model where information is stored in
related structures called tables or relations.
2. Table: a structure used to store related records.
Records: related field that represents a single item or entity.
Field: logical combination of characters that can be manipulated
as a unit.
3. Objects which help the user easily manipulate and manage data
in a database include:
 Tables, forms, queries, reports, macros, modules.
4. To start MS-Access, click start, point to programs then click MS-
Access. To exit, click file then exit or simply click the close button
on the title bar.
5. Query: a database feature used to analyse data in a table.
Macro: a feature used to automate database operations.
Module: a programming environment embedded in MS-Access
used to automate database operations. 129

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

Answer of review questions 2


1. Primary key – unique field used to identify each record uniquely
for easy access and manipulation.
An index – a key not necessarily unique used to arrange data in a
table.
2. Normalisation – a technique used to make a complex database
more efficient by breaking one large table into smaller related
tables.
3. Text, number, date/time, logical (yes/no), etc.
4. Setting validation rule:
A) Select the field you want to set validation rule to.
B) In the field properties section, click the insertion pointer in the
validation rule cell.
C) Type in the validation rule e.g. BETWEN 0 AND 100.
5. Field properties – characteristics of a field such as size, format,
etc.
6. Field name is a combination of characters that identifies a data
item whereas a caption is a full desc 131

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

Answer of review questions 3


1. Form – user interface that helps the user view records and easily
make entries into a table.
Bound controls – data field in a form layout grid that is used to
display data from the underlying table query.
Unbound control – data field in a form layout grid that is not based
on any data source.
2. Columnar form – display one record at a time with the fields
arranged downwards.
Tabular form – records are displayed across the screen from right to
left.
3. Click the design view from new form dialog box to display the form
design grid.
4. To provide an interface that let the user enter and view data easily.
5. Using the navigation button.
6. Student to use a word processor to sketch the form layout.

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

Answer of review questions 4


1. Query and find command.
2. A feature used to eliminate chances of entering non existing data
into child table., that do not exist in the primary table.
3. A table is a structure used to store related records while a query is a
component used to analyse data in a table.
4. Between 90,000 and 240,000.
5. 1). Click the cell that you want to use to sort a query in the sort row.
2). From the drop down list, select the sort order, i.e. descending or
ascending order.
6. Select query is used to search and analyse data in a table while
action query is used to make changes to underlying query or table.
7. Access gives a warning message and denies the user from entering
the next record.
8. Insert the totals function in a query then select SUM and AVG.

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

Answer of revision questions


1. Report – used to give a summarised information for the
purpose of presentation.
2. A report gives a summarised information for the
purpose of presentation while a label is a sticker placed
on an item for the purpose of identification or
description.
3. To create a report that displays subtotals and grand
totals, click summary options button in the report wizard
or create calculated controls in the report design grid in
the grouping field footer and report footer respectively.
4. Macros and modules.
5. See creating reports. To insert logo and drop it in the
page header in the report design grid.
137

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.

C) Enter ten records into


139
the table.

Practical activity 3-1


Field name Data type
 Create a table
Student number Text
named Exams in
First name Text
a COLLEGE
Last name Text
database with the
Maths Number
fields:
Physics Number
Chemistry Number
Computer Science Number
Total Number
Position Number
Reporting Date Date/Time 140

70
14/07/2023

Practical activity 3-2


 Set the Student number as the primary key.
Using a data form, enter data for five students as
follows.
Student No. MATHS PHY CHEM COMPUTER
2001 40 50 40 90
1983 60 70 57 30
2002 80 30 37 70
1513 30 63 80 70
141

Practical activity 3-3


 Without using the form wizard, create a form for
the exams table such that the format is
displayed as below:

Student Name ………. Student Name ………. Total ……….


Position ……….
Reporting Date ……….
Subject Average Marks
Maths ……….
Physics ……….
Chemistry ……….
Computer ……….. 142

71
14/07/2023

Practical activity 4-1


 You Are the database manager, Riceland
SACCO society and you are expected to create
a database called Riceland.
1. Design two tables in the database, employees
and bill with the following fields:

143

Practical activity 4-2


 Enter the following records in the employees’ table:

PNo National First Last Date Salary Sex


ID Name Name Employed
201 12234 Ali Mohamed 16-3-2002 40000 M
203 22734 Alice Korir 16-5-2002 37000 F
207 22734 Daniel Karimi 16-3-2003 60000 M
208 12234 Pateicia Atieno 16-3-2004 38000 F

144

72
14/07/2023

Practical activity 4-3


 Enter the following records in the bills table
PNo Bill No Date Employed Salary
201 1100 9-7-2004 3,000
203 1200 16-7-2004 7,000
201 2000 24-7-2004 2,000
208 1340 16-6-2004 800
204 1430 18-7-2004 1,700

145

Practical activity 4-4


 Create a calculated query based on the
two tables that will calculate and display
the following:

A) The total bill for Joe in the month of January

B) The total bill for all the employees.

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

You might also like