Chapter Seven Database Management Systems (1)
Chapter Seven Database Management Systems (1)
These are software that allow records to be entered in the system and to be
retrieved in a specified format. Examples are Ms Access, Paradox, Dbase, FoxPro,
Sybase.
From the above examples, we shall look at Ms Access.
7.1 MS ACCESS
MS Access is a database tool used to store, maintain and use a collection of
information that is organized to serve a specific purpose.
Database objects
Tables, Queries, Forms, Reports, Macros, Modules.
Tables
Collection of data about a specific subject e.g. customers, employees e.t.c.
In a table, data is organized in fields (columns) and records (rows)
A table consists of:
(a) Field names
(b) Data types
(c) Description
(a) Field name: - these are column headings for the table being created.
(b) Data types: - the attribute of a field that determines the type of data it can
hold e.g. text, Numeric, Currency etc.
(c) Description: - This column is optional but can be used to give a detailed of
the field name.
Primary key: - This is a field that is used to uniquely identify each record
stored in a table.
Queries
A query is a type of database search. It enables you to retrieve data that has met
conditions you specify, indicating data from tables.
The word „query‟ literally means „to ask‟. Access queries provide a way of asking
about your data. When you design a query, you identify the fields to be included
and the records to be retrieved from one or more tables.
You can as well update or delete multiple records at the same time, perform built
in or custom calculations on your data.
Forms
They are used for adding new data, editing or displaying existing data. This data
can be in a table or a query. Information entered directly in a form will appear in
Tables automatically.
Reports
Modules
They are collection of codes using Access Basic programming language. If
programming is necessary, you can write modules.
Database definitions
1. Field: This is any piece of information in a database e.g. Names, Age, Birth
date.
2. Record: It is a collection of several related fields.
3. Database File: This is a collection of several records.
Applications of databases
1. Educational applications: Preparing students‟ reports, class schedules.
2. Retail applications: This may include sales projections and Quotas,
Market analysis e.t.c.
3. Legal applications: This may include client information and case
schedules.
4. Financial applications: This may include stock market forecasting and
end of year financial reports.
PLANNING REQUIREMENTS
In order to plan an efficient database you need to ask yourself some
questions, these include.
The subject/object here is a student and the suggested field names could be;
i) Student‟s name
ii) Student‟s registration number
iii) Student‟s address
iv) Parent‟s name
v) Age
vi) Sex
vii) Course taken
viii) Subjects
ix) Hours a subject takes
x) The lecturer
xi) Lecture‟s rate per hour
xii) Tuition fee
xiii) Course duration
xiv) Date of admission
xv) Amount paid
All the above listed is information about one object – student. There is need
however to limit the list to the subject area only.
Let us assume we wish to store student fee payment records only. This will
reduce above list to the following.
i) Student‟s name
ii) Student‟s registration number
iii) Student‟s address
iv) Course taken
v) Age
vi) Sex
vii) Date of admission
viii) Amount paid
NB: The database name (Macarl student record system) is displayed on the title
bar of the database window.
7.3 WORKING WITH TABLES
1. Click new (after clicking the tables tab)
2. „A new table‟ window appears. You can create a new table with the
different options listed.
3. Select the design view and click Ok.
4. The „table window‟ appears with field name, data type and description
columns (as discussed in tables earlier)
5. In the Field name, type the first field i.e. assuming we are creating a
table on students, one suggested field could be Student name.
Therefore, type Student name.
6. Click data type column and select the data type, (in this case text)
7. Click the description column and describe the field you have just
made. However it is optional and could be skipped.
8. Define all other student‟s detail fields by repeating steps 5-7.
9. Close the table and respond affirmatively to „save changes‟ dialog box.
Save the table as „students‟
NB: your database now has one table object.
DATA TYPE USE EXAMPLE
A unique field is required in every table. This is an identification key like the
national ID card that identifies each person individually. The unique key is
referred to as primary key in Access. It is useful when you want to avoid
entering duplicated records.
If what you design does not have a unique field, Access lets you include a
special field called AutoNumber which contains sequential or random numbers
that Access automatically generates as you add new records.
Setting a primary key
1. In the table design view, click inside the key you want to define as the primary
key.
2. Click edit from the menu, move to primary key and click.
N/B: If Access has already taken AutoNumber as the primary key, delete the
record by choosing it from the border and pressing delete key from the
keyboard.
N/B:
Datasheet view allows you to add records while you modify the table in
design view.
You can rename a field in data sheet view by double clicking the field and
typing a new name
Sorting helps to quickly locate the highest or the lowest value in a list E.g.
you can sort to know who has paid the highest amount.
It also helps arranging data in order of priority.
Procedure
1) Position the cursor in the field you want to sort.
2) To sort in ascending or descending, click records from the menu bar.
3) Move to sort and choose as desired.
7.4 RELATIONSHIPS
After setting up different tables for each subject in a database, there is need to let
access know how to bring the information back together. The first step in this
process is to define relationships between the tables. After that, queries, forms,
reports can be used to display the information from all the tables at once.
A one-to-one relationship
In a one-to-one relationship, each record in Table A can only have one matching
record in Table B and each record in Table B can have only one matching record
in Table B.
A one-to-many relationship
A one-to-many relationship is the most common type of relationship. In a one-to-
many relationship, a record in Table A can have many matching records in Table
B, but a record in Table B has only one matching record in Table A.
A many-to-many relationship
In a many-to-many relationship, a record in Table A can have many matching
records in Table B, and a record in Table B can have many matching records in
Table A. This type of relationship is only possible by defining a third table (called
a junction table) whose primary key consists of two fields, the foreign keys from
both Tables A and B. A many to many relationship is really two one-to-many
relationships with a third table.
7.5 WORKING WITH QUERIES
Creating a query
Query is a database search. It enables you retrieve data that meets certain criteria.
You can use a query to create a table, a report or a form. When you have a
frequently asked query, you can save it so that each time you need the
information, you just run the query instead of opening the table.
Saving a query
1. Close the query box by clicking „X‟ button
2. Click yes when prompted to save the query.
3. Type the name of the query in the „save as‟ dialog box. In our case „students
balance s‟
4. Click Ok
Procedure
1.Create a new query in the design view.
2. Select the table that you want to update records.
3. Add the field/s you want to update in our case „amount paid‟
4. Click „query „ from the menu bar, click „update query‟. This changes the query
from a select query to an update query.
The ‘update to’ row is added.
5. Select the field(s) to be updated (In this case amount paid)
6. In the „update to‟ cell, type in the expression that you will use to update
information in your table.
Example: You may decide to raise the fees by 1000,therefore you type [amount
paid]+1000 in the „update to‟ row of the amount paid field.
7. Run the query.
8. A warning appears informing you that the action cannot be reversed.
9. Click Yes to update the records.
10. Close the query and save the changes.
NB: An update query does not open the records when double clicked, Instead you
should open the table that you run the update query on to view the results.
TYPES OF TOTALS
Types of Calculations Used to calculate
Sum The total values in a field
Average The average values of a field
Minimum (Min) The lowest value in a field
Maximum (Max) The highest value in a field
Count The number of values in a field
StDev The standard deviation of values in a field
Var The variance of values in a field
First The field value from the first record in a table or a
query
Last The field value from the last record in a table or a
query
A parameter query is a query that when run displays its own dialog box
prompting you for information, such as criteria for retrieving records or a value
you want to insert in a field. You can design the query to prompt you for more
than one piece of information; for example, you can design it to prompt you for
two dates. Microsoft Access can then retrieve all records that fall between those
two dates.
To prompt the user for one or more characters to search for, and then find
records that begin with or contain the characters the user specifies, create a
parameter query that uses the LIKE operator and the wildcard symbol (*). For
example.
For a field that displays dates, you can display the prompts "Type the beginning
date:" and "Type the ending date:" to specify a range of values.
Procedure
7.6 FORMS
Procedure
1) In the database window, click the tables tab then click new or use an
existing table.
2) Click design view then Ok
3) Designate one of the field for the O.L.E. The field name could be photo,
picture etc. For its data type, select O.L.E. objects.
4) Close the table and save the changes.
5) Open the table.
6) Right click the O.L.E fields(s) then insert object.
7) From the object type list, select a category i.e. Microsoft clip gallery then
click Ok.
8) Select a clip then click insert.
NB/ The object will always be seen whenever you open a form based on the
table or query that has the O.L.E field.
7.7 REPORTS
Reports are used to analyze data or present it in a certain way in print. A report
could be that which groups data and calculates totals and another different data
formatted for printing mailing tables.
Procedures
Required
1. Create a data entry form in design view and apply your own
design in the form
2. Enter the above records using the form above
3. The semesters fees is 60,000 Kshs. Produce a list of
students who have cleared the fees
4. Produce a list of Female students taking a course in education
5. Produce a list of students who were born before the year 1990
6. Product a report that will show the current students
grouping them by their respective courses
7. Prepare a report showing a list of students who have cleared their fees
8. Prepare a macro that will open no 3 above and open the report on 7
above.