Module No.2.0: Office Application Unit No.2.3: Database Application Element 2.3.1: Selecting Database
Module No.2.0: Office Application Unit No.2.3: Database Application Element 2.3.1: Selecting Database
0: OFFICE APPLICATION
UNIT NO.2.3: DATABASE APPLICATION
ELEMENT 2.3.1: SELECTING DATABASE
WHAT IS A DATABASE?
DATABASE: Is an organized body of related information that is arranged for ease and speed of
search and retrieval.
Example of databases include: School management system, address books, human resource
management system etc.
SPREADSHEET VS DATABASE
• A spread sheet is an application for tabulating data while a database is where data is
stored so that it can be retrieved by users (Spreadsheet = calculator
Database = information storage/retrieval system)
• The amount of data that is usually stored in a database is way more than what is
contained in a spread sheet
• A spread sheet is edited directly by people while a database is accessed by applications
that enter and modify data
• A spread sheet is usually used for presentations and paper works while databases are
commonly used in cases where a lot of data needs to be stored
With Microsoft access DBMS you can perform tasks such as storing, filtering, and retrieving
data, as well as asking questions about the data and receiving instant answers.
Before creating and working with a database, it is important to understand what a database is
made of:-
• Database data is organized in tables. Tables consist of records and fields.
• Database tables are always related to each other and a database that contains related
tables is called a RELATIONAL DATABASE.
• TABLES are used to enter, store, organize and view database data.
A key field is a unique field in a database table. That means within a key field not more than
one record will contain the same data.
a) Primary key
b) Composite key
c) Foreign key
PRIMARY KEY: This is a field in a database table that uniquely identifies a record. E.g.
Employee’s identification number.
COMPOSITE KEY: This is when two or more fields are used as a primary key. E.g. in a school
database table fields such as examination number and registration number may act together
as composite key.
FOREIGN KEY: Is a field (or fields) that point to the primary key of another table. The purpose
of the foreign key is to ensure referential integrity of the data in the two relating tables.
Amount
the above example, the Customer ID column
in the ORDERS table is a foreign key pointing
to the Customer ID column in the CUSTOMER table.
RELATIONAL DATABASE
A relational database is the one having its tables connected (related) with each other using
the key fields.
Key fields that connect two tables must have certain fields in common between them.
a) ONE-TO-ONE
b) ONE-TO-MANY
c) MANY-TO-MANY
ONE-TO-ONE RELATIONSHIP: This is when one record in one table points (relates) to only one
record in another table.
ONE-TO-MANY RELATIONSHIP: This is when one record in one table relates to several records
in another table.
NOTE: In order to relate the two tables, you will have to copy the primary key from the ONE
side and insert it into the MANY side as a foreign key.
Example:
MANY-TO-MANY RELATIONSHIP: This is when many records in one table relate to many
records in another table.
NOTE: Unlike other types of relationships, to create a many-to-many relationship you need to
create an intermediary table that will hold primary keys from the two tables.
REFERENTIAL INTEGRITY
REFERENTIAL INTEGRITY: Is the ability to maintain links between database tables. In other
words Referential integrity is a database concept that ensures that relationships between
tables remain consistent.
a) You may not add a record to a child table unless the mother table is filled first.
b) If the primary key for a record in the mother table is changed, all corresponding fields
in the other table must be modified using a cascading update.
c) If a record in the Mother table is deleted, all corresponding records in the other table
must be deleted using a cascading delete.
DATA TYPES
After you name a field, you must decide what type of data the field will hold. Before you begin
entering data, you should have a grasp of the data types that your system will use. Some basic
data types are shown in the table in the next slide; some data types (such as numbers) have
several options:
DATA TYPE USE FOR
Currency Currency values. Use the Currency data type to prevent rounding off
during calculations.
Yes/No Fields that will contain only one of two values, such as Yes/No,
True/False, On/Off.
DATABASE SCHEMA
You can design a schema by using drawings or just text. The example below shows a
database schema written in text.
Tables: Book (Book ID, Title, Theme, Year, Page Count, Cover Picture, Author ID)
Author (Author ID, First Name, Last Name, Date of Birth, Nationality)
Borrower (Borrower ID, First Name, Last Name, Title)
Book Borrower (Borrower ID, Book ID, Borrow Date, Due Date, Returned, Overdue
Fine, Fine Paid, Fine Balance)
The above example shows a database schema with database name Book Library composed of
four tables Book, Author, Borrower and Book Borrower.
To change the data type for the Primary key field do the following:
1. Make sure that the Primary key field is selected (the column heading should have an
orange background).
2. In the Data Type & Formatting group on the Datasheet tab, click the Data Type arrow,
and then click Text or other data type.
To define a relationship:-
Click the Database Tools tab on the Ribbon.
In the Show/Hide group on the Database Tools tab, click the Relationships button. The
Show Table dialog box opens.
Add tables to the Relationship window.
Click Close button in the Show Table dialog box to close it.
Click a common field in one table, and then drag it to the common field in another
table. When you release the mouse button, the Edit Relationships dialog box opens.
Click the Enforce Referential Integrity check box, and then click the Cascade options
check boxes.
Click Create button to define a relationship between the two tables.
ENTERING RECORDS
To enter records in a table datasheet, you type the field values below the column headings for
the fields. The first record you enter will go in the first row below the field names.
SAVING A TABLE
After you add fields and records to a table, you need to save the table’s design. The records
you enter are immediately stored in the database as soon as you enter them; however, the
table’s design (the field names and characteristics of the fields themselves are not saved until
you save the table.
NOTE: When you save a new table for the first time, you should give it a name that best
identifies the information it contains.
To save a table:
Click the Save button on the Quick Access Toolbar. The save As dialog box opens.
In the Table Name text box, type the name for the table.
Click the OK button.
OPENING A TABLE
Any table you create and save is listed in the Navigation Pane. You open a table, or any Access
object (query, form, report), by simply double-clicking the object name in the Navigation
Pane. Next, you’ll open the table so that you can see the order of all the records you’ve
entered.
Quick Exercise
In queries you can pull data from several related tables to get an answer to a specific
question. In a response to a query, Access displays the specific records and fields that answer
your question.
Access provides powerful query capabilities that allow you to do the following:
CREATING A QUERY
When you create a query, you tell Access which fields you need and what criteria Access
should use to select the records. Than Access displays only the information you want, so you
don’t have to navigate through the entire database for the information.
You can design your own queries or use an Access Query Wizard, which guides you through
the steps to create a query.
CREATING A QUERY BY DESIGN
1. Click the Create tab on the Ribbon. Access displays the options for creating different
database objects.
2. In the Other group on the Create tab, click the Query Design button. The show table
dialog box opens on the Query window in Design view.
3. The show table dialog box lists all the tables in your database. Click a table in the
Tables list box, then click Add button, then click Close button.
4. Access places that table in the Query Window and you can now choose which field to
be displayed in a Query.
5. Thereafter, click Run button (!) to display query results. Access runs a Query and
display results in Datasheet view.
6. Click the save button to save a Query.
A QUERY EXAMPLE
1. Which Authors wrote books which were published before the year 1990?
ANSWER: Create a query by selecting “First Name” ,” Last Name” fields from Author
table and the “Year” field from Book table. Add “<1990” criteria in the Year field.
ANSWER: Create a query by selecting “Book ID”, “Returned” field from Book_Borrower
table and “Title” from Book table in the order of (Book ID, Title, and Returned). Add a
“No” criteria in the Returned field.
3. A list of books showing only Book title and the year of publication.
ANSWER: Create a query by selecting “Title” and “Year” fields from the Book table.
NOTE: You can create a query by using fields from more than one table only if those tables are
related and you have set relationships between them.
MODULE 2.0: OFFICE APPLICATION
UNIT 2.3: DATABASE APPLICATION
ELEMENT 2.3.4: CREATING FORMS
FORMS
• A form is a database object used to enter, view and manipulate records in a table or
query in a more simple way.
• Forms are an easy way to enter, edit and view data.
• Any table or query can be converted into a form.
• Forms can include fill-in-the-blank fields, check boxes, lists of options e.tc.
• Forms can also contain buttons that allow the user to perform other actions, for
example to print reports or labels.
In Access, there are many different ways to create a form. You can design your own forms, use
the Form Wizard, or use the Form Tool to create a simple form with one mouse click. The
Form tool creates a form containing all the fields in the table or other database object on
which you are basing the form.
To view and maintain data using a form, you must know how to move from field to field and
from record to record. Notice that the form contains navigation buttons, similar to those
available in Datasheet view, which you can use to display different records in the form
NOTE: To see other records, use the Navigation bar at the bottom of the window.
• Once you have created your form, you can enter data or format the form to suit your
needs.
• To add a new record, click on the new record button in the navigation bar.
• To use the formatting options, click the design view button from the database toolbar.
MODULE 2.0: OFFICE APPLICATION
UNIT 2.3: DATABASE APPLICATION
ELEMENT 2.3.5: CREATING REPORTS
PRINTING A REPORT
After creating a report, you typically print it to distribute it to others who need to view the
report’s contents. You use the Print command available from the Office menu to print a
report.
Open the report in in any view, or select the report in the Navigation Pane.
To print the report with the default print settings, click the Office button, point to
Print, and then click Quick Print.
Or
To display the Print dialog box and select the options you want for printing the report,
click the Office Button, point to Print, and then click Print (or, if the report is displayed
in Print Preview, click the Print button in the Print group on the Print Preview tab).
REVIEW QUESTIONS
1. Define a database?
2. Differentiate between a spreadsheet and a database.
3. Differentiate between a database and a database management system (DBMS).
4. Outline three examples of DBMS.
5. Outline the procedures you need to follow when creating an Access database.
6. Tables, Queries, Forms and Reports are some of the Access database objects. Describe
each of these objects.
7. What is a key field?
8. How many types of key fields are used in database? Mention them.
9. Is it necessary for each table in Microsoft access to have a primary key?
10. Differentiate between Primary key and Foreign Key.
11. What is the importance of creating relationships within database tables? Describe how
you would create relationships in Access database.
12. Distinguish between RECORDS and FIELDS.
13. What is referential integrity as applied in relationships?
14. What do you need to prepare if you wish to print your database tables, queries or
forms or export to other formats e.g. ms word?
15. Mention five examples of data types which are used in Access database.
16. What is the advantage of entering data in a form?
17. Describe types of relationships in a database.