0% found this document useful (0 votes)
63 views51 pages

Computer Studies Form 2-Database

Uploaded by

hezronmukhwana54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views51 pages

Computer Studies Form 2-Database

Uploaded by

hezronmukhwana54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 51

FORM 2 COURSE WORK

DATABASE

Ref: Longhorn BK 2, KLB log on BK 2, Log On To IT for


CSEC,
Top mark revision, Internet resource.
By the end of the topic, the learners
should be able to:
Define the term database.
Describe database models.
Create a database.
Apply database objects in the database.
Print tables, queries, forms and reports
INTRODUCTION:
Definition of terms:
Database:
It is an organised collection of structured
and related data held in a computer or
electronic device and whose accessibility is
controlled. It is considered to be organised
because the data is stored in categories
that are accessible in a logical manner.
A database is also a common data pool
maintained to support the various activities
taking place within an organisation.
Data:
Referred to as anything that is deemed to be
of significance to the organisation that the
database system is serving.
Databases cannot be created once and for
all, but their creation and maintenance is
a gradual and continuous process.
The creation and maintenance of databases
is under the influence of a suit of system
software known as Database Management
System (DBMS). The users of the
database communicate their requirements
to the database using Data Description
Languages (DDL) and Data Manipulation
Languages (DML) via the DBMS.
DBMS provides an interface between the
user programs and contents of the
database.
Database systems are installed and
coordinated by database administrators.
Functions of a Database Management System
(DBMS):
i. Interfaces the users of the database contents
through data manipulation languages.
ii. Constructs the database contents through data
manipulation languages.
iii.Ensures the growth of database by adding new
fields and records
iv.Maintains the contents of the database, an
activity that involves, adding new records,
modifying existing records, removing obsolete
(inactive) records etc.
v. Manages the storage space for the data within the
database and keeps track of all the data in the
database.
vi.Ensures the security of data in the database
through passwords and data encryption.
vii.Places data in an organized manner for easy
retrieval and manipulation.
viii.Ensures data integrity when records are being
entered in the database.
Components/elements of a database:
(a) Character
(b) Field
(c) Record
(d) File

(a)Character
It is the smallest element of a
computer file and refers to a letter or
symbol that can be entered, stored
and output by a computer. It is made
up of a set of seven or eight digits
depending on the character coding
scheme used.
(b) Field(s)
Refers to a single character or collection of
characters that represent an attribute
within an entity. Fields have unique data
types.
It is also a column of similar information or
groups of vertically related data that
contain similar information of the same
data type.
Data types are field properties that apply
to all values contained in that field and
determines what kind of data those values
can be.
Data types can be of text, number,
currency and date/time. Fields appear in
columns within a table structure.
(c) Record
Refers to a collection of related fields for
an entity. Records in a file are made up
of fixed number of fields. For example,
an individual employee record may
include his name, employee number,
salary, tax, gender etc. records are
recorded in rows within a table structure.
(d) File
A file is a compilation of related data
records maintained in some prearranged
order. For instance, an employee file
might consist of 1,000 individual
employees arranged by the employees
number.
Database system
It comprises of four major components.
They include:
i. Data: these are values physically recorded
in the database. They are the raw values
and facts. Data is also referred to as
anything that is deemed to be of
significance to the organisation that the
database system is serving.
ii.Hardware: it consists of secondary
storage devices on which the database
resides together with the associated
devices control units and communication
channels.
iii.Software: application programs that
allow users to store information in an
ordered manner for timely and quick
retrieval such as a DBMS.
(iv) Users: refers to the person who uses the
DBMS. There are three broad categories of users.
They include:
 Application programmers: They are responsible
for writing programs that use the database. They
use the DBMS to come up with software that can
solve problems for specific groups of people or
organisations.
 End users: they interact with the database from
a terminal. The end user may employ a query
language provided as an integral part of the
system. They use the DBMS to solve individual
problems.
 Database administrator: the persons who have
the overall charge of the database system. They
exercise administrative functions such as
ensuring security of data by defining the access
Examples of DBMS:
DBMS can be divided into two categories namely:
 Desktop databases.
 Server databases.
Desktop databases are single user applications
that reside on standard personal computers;
hence the name Desktop. They include the
following:
 Microsoft Access
 Fox Pro
 Paradox
 Lotus Approach
 FileMaker Pro
 Clipper
 Dbase
Server databases contain mechanisms that
ensure the reliability and consistency of data
and are geared towards multi-user applications.
They are designed to run on high performance
servers and they carry a corresponding high
price tag. They include the following:
 SQL server
 Oracle
 DB2
 Ingress
Entity Relationship Modeling
It is a technique used to identify the objects
within an organisation and how they are related
to each other.
It uses the concept of entities, attributes and
relationships.
(i) Entity
An entity is an object of significance, whether real
or imagined about which information needs to
be known or held e.g. a person, car, house,
company, student, course and job.
(ii) Attribute
An attribute is any detail that serves to qualify or
express the state of an entity. It could be text,
numbers, picture, a feel, smell, sound etc.
Illustration: A student entity could have the
following attributes:
FEES PAID

ADDRESS STUDENT ADM/NO

NAME
(iii) Relationships
It is defined as an association among entities. Several
relationships may exist between the same entity. There
are three types of relationships recognised among various
data stored in a database. They are as follows:
(a)One To One Relationship
This is where one record or entity in a primary table/file is
linked to exactly one record or entity in another file/table.
Examples;
-A movie cannot be loaned to more than one person at the
same time.
-A student can only have one admission number and an
admission number can only be issued to one student.

STUDENT ADM/NO

PERSON MOVIE
(ii) One to Many relationship
One record or entity in a table/file is linked to
many records or entities in another table/file.
Examples;
 One person can borrow many movies and many
movies can be borrowed by one person.
 A student can register for one course and many
students can register for that particular course.

student
Movie 1
1

student
person Movie 2 course 2

student
Movie 3
3
(iii) Many to Many relationship
Many records/entities in a primary file/table are linked to
many records/entities in another file. Examples;
 A movie can have many actors and an actor can act in
many movies.
 A trader can sell many items and many traders can sell a
particular item.

movie actor

trader item
Database Models:
It is a specific method for describing the structure,
organisation and processing within a database. There
are five types of database models namely:
a) Flat file or File Management System (FMS) model.
b) Hierarchical Database system (HDS) model.
c) Network database system (NDS) model.
d) Relational database model.
e) Object oriented model.
(a) Flat file or File Management System (FMS) model
It was the first method used for data storage in a
computerised database. The data is arranged
sequentially in a given order. To access a particular
item, the search begins at the first item and
subsequent items are checked until the required item
is located.
(b) Hierarchical Database system (HDS) model.
In this model, data items are arranged in a tree
format. The origin of a data tree is a root
(level 1). The subsequent levels are called
nodes which branch to the lowest level called
a leaf. To access an item, in level 2, level
1data items have to be accessed. A specific
single path leads to each item at lower levels.
This model is used in storage ofROOT
files in a
(LEVEL 1)
computer, where the root directory is either
C:, A: or D:. (it forms a one to many
relationship) NODES
(LEVEL 2)
(c) Network database system (NDS) model.
In this model, data relationships and items link
to each other in the form of a network. The
relationship between the data items is
known as sets. Data items are accessed
through multiple paths. It forms a many to
many relationship. The model uses a pointer
to locate a particular record.
However, in case of large volumes of data, it is
difficult to locate an item because it will
increase the complexity of the search due to
the use ofTrader 1
the pointer. Trader 2

Item 1 Item 2
(d) Relational database model
This model organises data in simple row column
format called tables. Related data items are
entered in a table where each column
represents individual fields and each row
represents individual records. This method is
popular
Students detailswith
table mini and micro computers.
Students marks table
Relationships
Adm/no Name
can be createdKCPE
Adm/no
amongst
mark
various
tables. Joseph
7009 7009 300
7010 Hansel 7010 324
7011 Mary 7011 410
7012 Royale 7012 312

Adm/no Name KCPE mark


7009 Joseph 300
Students and
marks table 7010 Hansel 324
7011 Mary 410
7012 Royale 312
(e) Object oriented model.
In this model, objects appear as independent entities
which can relate with other objects in the database.
The technology of this model is still under
development.
Data Integrity
It refers to the accuracy, completeness, timeliness and
relevance of data in a database and throughout its
subsequent processing.
The constraints imposed restricts and validates the data
values that are added or updated in the database.
These constraints include:
(i) Validity integrity: It checks if the data entered within
fields matches the field data types defined. For
instance, if a field ADM.NO is defined to be of number
data type, then data containing alphabetical
characters cannot be accepted in that field.
(ii) Entity integrity:
It checks for duplication of data among entities
done through the use of a primary key (a
unique identifier for each entity).
(iii) Referential integrity:
It ensures that the relationships established
within the data base are correct.
It ensures that a value entered in one field of a
linked table (related table) matches an
existing value in the related field of the
primary table.

MICROSOFT ACCESS
Ms Access is a DBMS application within the
Microsoft Office Suite use for creating and
manipulating databases. Currently, there
exists various versions of Microsoft Access.
Creating A New Database In Microsoft Access
2007
Getting started:
Steps:
 Click START menu
 Select PROGRAMS/ALL PROGRAMS
 Click on MICROSOFT OFFICE folder
 Select MICROSOFT ACCESS
 In the Getting Started With Microsoft Access task
pane, under New Blank Database, click on Blank
Database.
 In the Blank database task pane that appears, under
FILE NAME, type an appropriate name for the
database.
 Click on CREAT button.
A new database will appear ready for construction and
interaction with database features such as tables,
queries, forms and reports.
Microsoft Access 2007 start window
Microsoft Access 2007 window
Features of Microsoft Access 2007 Window
Ms Access window is divided into two major
parts:
i) The application part- it contains the tabbed
menu ribbon with tabs such as:
 Home
 Create
 External data
 Database tools
ii) The Database window- it contains a navigation
task pane that displays created database
objects such as:
 Tables
 Queries
 Forms
 Reports
 Macros etc.
Ms Access database objects:
 Table: It is a database object made up of
rows and columns that is used to hold
related data records. Each row
represents a record while each column
represents a field.
 Queries: it is database tool used to
extract data from one or more tables
based on a specific criteria and display
the result.
 Forms: these are data entry screens
that provides the user with graphical
interface to enable them add, view,
delete and edit records.
 Reports: these are database tools that are
used to summarize and present data from
tables and queries and format them in a
suitable way for viewing or for printing.
 Macros: it is an automation database tool
that enable users to add functionality to a
database. They contain actions that perform
tasks such as opening a report, running a
query or closing the database.
 Modules: Visual Basic Application
procedures that can be used to automate
more complex operations that cannot be
handled by macros.
Guidelines for designing a good database
 Study carefully the user requirements in order
to define all the data inputs, outputs and the
relationships required.
 Design a draft database on the paper to
determine the number of files or tables
required.
 Divide the information into separate fields,
records and tables to allow flexibility in
manipulating the database
 Define a field for each table that will be used
to identify each record uniquely (primary key).
 Give the most important fields priority when
constructing a table structure.
 Design data entry screens (forms) needed for
the database.
Database objects:
i) TABLES/FILE STRUCTURE
It is a database object made up of rows and
columns that is used to hold related data
records.
Each row represents a record while each column
represents a field.
Creating a table structure
A table can be created using table wizard, table
templates or in design view.
Description of Field data types
A data type refers to the attribute of a field that
determines the kind of data it contains.
Common data types are as follows:
Table design view Window showing field names, data types and
field properties
DATA TYPE DESCRIPTION
Text This type includes alphabetical letters,
numbers, spaces and special symbols. It can
take a maximum 255 characters including
spaces. It usually specifies a field that is
not used for calculations including numbers
stored in it.

Memo It is similar to text and stores lengthy text


such as notes and descriptions up to 65536
characters in length. It cannot be used in
queries or as a primary key.
Number Fields made up of numeric values 0 to 9
including mathematical operators. They are
used in calculations.
Date/time Stores different formats of date and/or time.
This can also be used in calculations.
Currency Used to store currency values. It prevents
rounding off during calculations. The default
symbol is the dollar ($) sign.
AutoNumber It is numeric in nature and enables Ms Access to
automatically increase values each time a record
is added.
Yes/No Defines a field that can only accept two values;
Yes/No, True/False or On/Off.
OLE Object OLE stands for Object Linking and Embedding. It
enables a field to accept a graphic input and is
used in inserting pictures, drawing charts or
inserting Ms Excel workbook in a database.

Hyperlink Used for storing web page addresses. It also


enables Ms Access to start your web browser and
display the web page whose address is stored in
the field.
Field Properties
Properties determine how a field is stored, works and how
it is displayed. Ms Access automatically assigns default
field properties to such field depending on the data
type. It contains two tabs that can further be used to
put restrictions on a field. They include the General Tab
and the look up tab.
General tab: has the following properties:
 Field size: used to determine the length of text and
number data types. It limits the number of characters
being entered and can save disk space or even prevent
data entry errors.
 Format: this property affects how data values are
displayed on the screen and when printed.
 Decimal places: it applies to number and currency fields
and helps one to determine the number of decimal
places.
 Input mask: it enables user to define a character string
to act as a template so that data entered is formatted
in a specific way.
 Caption: this is a more descriptive name for a field to
be used in a table or a form display. It accepts
punctuations in field names e.g. Admission Number as a
field name can be written as Adm. No. in the caption
property.
 Default value: this is a value that appears automatically
in the datasheet or a form if nothing is entered to
change it e.g. =Date () automatically displays the
current date in the date field.
 Validation rule: logical expression that restricts the
values to be entered in a field e.g. if you want to
restrict marks entered in a field to values between 0
and 100, type >=0 and <=100.
 Validation text: this is the message that appears once
the validation rule is violated e.g. “you entered the
wrong values” message.
 Required: determines if an entry must be made in the
field before you proceed to the next field.
 Allow zero length: allows a user to proceed without
making an entry in the field set as zero length.
 Indexed: it facilitates the organisation of records for
easy search.
Setting a Primary Key
A primary key is a selected field that uniquely identifies
records within a database. An index is created when a
primary key is set; this speeds up the search operations
within a database.
Characteristics of a Primary key
 It is not allowed to be null value (i.e. leaving a field
blank indicates that there is no value for that field), it
must always have a unique value.
 It speeds up data storage and retrieval and the running
of queries.
 It sorts records according to the values in the field.
 Enables creation of relationships between tables so
that they can be joined.
Defining relationship between tables:
This is a way in which data in a table are related to another table.
This feature helps to reduce redundancy within a table.
A relationship exists only between fields with the same name,
records and data types. The records need not be of the same
number. This, therefore, means that a field must be repeated in
the different tables to be used in creating the relationship.
When a primary key is repeated in another table, it becomes a
foreign key.
The table that has the primary key is the parent’s table while the
one with the foreign key is the child’s table.

Primary key Primary key


Foreign keys

Parent table Child table Parent table


One to many Relationship among three tables
Forms
Forms are sometimes referred to as data input screens. It
is a user interface used for viewing and making entries
into a table more easily.
Forms can be designed for several different purposes. They
include;
 Displaying and modifying data.
 Accepting user input.
 Controlling application flow.
 Displaying messages.
 Printing information.
In design view, it is designed using graphical objects
called controls.
A control is an object placed on a form design grid to
display data or perform actions. Some of the form
controls include text boxes, labels, command buttons etc.
The controls are divided into three main categories:
i. Bound controls: these are fields of data that come from a
table or a query. A form must have a bound control for
each field that is displayed on the form. You cannot
create a calculation in a bound control. Text boxes are
the most common bound controls.
ii. Unbound controls: These controls contain a label or a text
box. They are used to explain or identify other controls
on the form. Calculations can be created from an
unbound control. It is not connected to any data source.
iii.Calculated control: these are controls created from
unbound controls that have values calculated in a form
including totals, subtotals and averages.
Forms can be created using form wizard, Autoform and in
design view.
Form/input screen
Form in design view
Form layout in design view:
 Form header: It is the first section of a form. It contains
the title of the form, or any other information that
remains constant in the form.
 Page header: it is the second section of the form. It
displays the field names at the top of every page.
 Detail section: it is the third section of a form and
contains records from a table or query or any other
unbound record.
 Page footer: it is the forth section of the form. It displays
current date and page numbers. The information is
displayed at the bottom of the page when the form is
printed.
 Form footer: it is used to display command buttons or
calculated control that displays totals of given fields.
NOTE: you can add controls from the toolbox to enhance its
appearance and presentation of data.
Creating Queries:
A query is database tool used to extract data from one or
more tables based on a specific criteria and display the
result.
It is a question posed to a table(s) and the result must
meet a condition or conditions specified in the criteria
section of the query.
This resulting collection of record(s) is called a dynaset
(dynamic subset). As the original tables are updated the
dynaset is also updated when the query is run (command
that executes the current query). Queries are mostly
used to:
 Select specific groups of records of records that meet a
given criteria.
 Combine information from two or more related tables into
one table/query.
 Perform calculations on fields from one or multiple
tables.
Using Microsoft Access, you can either write a query using
SQL (Structured Query Language) statements, or use the
Query wizard or Query design.
There are two types of queries:
1. Select query: it is the default query which extracts data
from tables on a criterion or specific value.
2. Action queries: they are used to modify data in an
existing table(s) or to create a new table. They include
the following:
 Make table query: it creates a new table from all or
some of the fields of data in one or more tables. These
queries are useful for creating tables to export to other
databases or other documents.
 Update query: it makes changes to a group of records,
or all records in one or more tables.
 Append query: adds a group of records from one or
more tables to the end of one or more tables.
 Delete query: deletes a group of records from on or
more tables.
Query design view Window-toolbars and menu items
Some options contained in the query design view
include:
 Field: enables a user to select from a list of
fields available in the table being queried.
 Table: enables the user to select the table
being queried. The tables also appear in the
upper section of the Query Window.
 Sort: enables arrangement of fields in a query
either in ascending or descending order.
 Criteria: enables the user to type an expression
setting a criteria to be met by a particular
field(s).
 Total: allows a user to group data in the active
query or perform summary calculation such as
sum, count, average, minimum, maximum and
standard deviation.
Common criteria in the Criteria Row:
Operator Description Example in use
Between..And Finds records between two Between #04/1/95#
values And #07/1/95#
Like Finds records that match a Like “th*”
criterion Like “*ing*”
Like “b?t”
Not Finds records that don’t Not In (1, 2, 3) Not
match a criterion Like “Sun*”
In Finds records that are part of In (100, 200,300,400)
a list
Wildcard characters
These are symbols used as placeholders for other
characters when you do not know exactly what you are
looking for, but part of the value is known. They are
also used to find values that start/end with a letter or
match a certain pattern.
Wildcard characters work with text and date data types.
A description of wildcard characters:
character Usage Example in use
* Matches any number of characters. wh* finds what, when,
It can be used as the first or last while, why etc.
character in a character string.

? Matches any single alphabetic B?ll finds ball, bell, bill,


character. bull
[] Matches any single character T[eo]ll finds tell, toll
within the square brackets. but not tall.
! Matches any character not in the B[!ae]ll finds bill and
brackets. bull but not ball and
bell.
- Matches any one of a range of D[a-d]d finds dad, dbd,
characters. dcd, ddd.
# Matches any single numeric 1#3 finds 103, 113,
character. 123, 133, 143, 153….
REPORTS (SCREEN OUTPUT)
Reports are used for displaying records obtained
from a table or query and to perform
calculations.
Reports can be created in three different ways just
like the forms i.e. design view, auto-report and
report wizard.
Types of Reports:
 Tabular report
 Column report
 Mailing label report
 Totals report
(expound on types of reports: KLB Log On Bk 2
page 159)

You might also like