Introduction to databases
Introduction to databases
Database
419
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.
420
210
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.
421
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
422
211
Disadvantages of traditional methods
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.
424
212
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.
425
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.
426
213
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.
427
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.
428
214
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.
429
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.
215
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. 431
216
Microsoft Access screen layout
2. Click “Exit.
217
Steps of “creating a table structure” 1
218
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”.
219
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.
439
220
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.
221
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.
222
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.
446
223
Field properties 6
Indexed – it facilitates the organisation of
records for easy search.
224
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.
225
Steps of “adding new records”
1. Double click the
table icon. (the table
is displayed in
datasheet view”.
2. On the “Insert”
menu.
226
Steps of “deleting records”
1. Click the record you
want to delete.
3. Click “Delete”.
227
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.
228
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”.
229
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”.
230
Steps of “adjust the column size”
231
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.
232
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.
233
Importing tables
You can import a table from another
database or a spreadsheet into your
database.
234
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
469
actions.
Types of controls
Bound – in this the source of data is a field
in a table or query.
470
235
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.
236
Steps of “create a form using the wizard” 1
237
Steps of “crating a form layout using form wizard” 3
238
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.
239
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.
240
Steps of “format controls on a form” (resize)
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.
482
241
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.
483
484
242
Steps of “creating a select query using wizard” 1
7. Select “Detail” or
“Summary”.
243
Steps of “creating a select query from in design view” 1
244
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.
245
Other examples of specifying the criteria search 1
246
Steps of “add fields into the query grid”
247
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).
2. Select “ascending”
or “descending”.
248
Steps of “delete fields from the query grid”
249
Steps of “modify a criteria statement, select query”
250
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).
251
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. 504
252
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. 505
253
Steps of “defining relationship between tables” 2
254
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.
255
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”.
256
Steps of “create a report layout using wizard” 2
257
Steps of “create a report layout using wizard” 4
258
Steps of “creating a report in design view” 2
259
Steps of “add more controls onto the report layout”
260
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.
261
Steps of “create a label using the report wizard”
262
Steps of “creating a label using the report wizard” 3
Modifying labels
Just as you can modify a report or a form,
you can also modify a label by
manipulating the layout controls
263
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.
264
Steps of “printing the reports and labels”
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.
265
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.
266
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.
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.
267
Steps of “setup a password in MS-Access” 2
268
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.
269
Steps of “assign user rights and privileges” 1
270
Steps of “assign user rights and privileges” 2
271
Steps of “assign user rights and privileges” 3
272
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. 546
273