0% found this document useful (0 votes)
91 views

Module No.2.0: Office Application Unit No.2.3: Database Application Element 2.3.1: Selecting Database

This document provides information on databases and database management systems. It discusses what a database is, the differences between spreadsheets and databases, examples of database management systems like Microsoft Access, MySQL, and Oracle. It also covers key concepts in databases like tables, records, fields, primary keys, foreign keys, relationships between tables, and maintaining referential integrity. Methods for creating database tables in Access using design view and datasheet view are also summarized.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Module No.2.0: Office Application Unit No.2.3: Database Application Element 2.3.1: Selecting Database

This document provides information on databases and database management systems. It discusses what a database is, the differences between spreadsheets and databases, examples of database management systems like Microsoft Access, MySQL, and Oracle. It also covers key concepts in databases like tables, records, fields, primary keys, foreign keys, relationships between tables, and maintaining referential integrity. Methods for creating database tables in Access using design view and datasheet view are also summarized.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

MODULE NO.2.

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

DATABASE MANAGEMENT SYSTEM (DBMS)

A database management system is an application to design and manage databases.


Examples of database management systems include Microsoft access, MySQL, Oracle and SQL
Server. All DBMSs are used for creating databases but differ in one way or another on how
databases are managed.

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.

RECORDS AND FIELDS


A record is a row in the table that contains information such as name, address, phone
number, etc.

A field is a column that contains categories of information.

NOTE: Each field in a table contains the same type of information.

EXAMPLE OF A DATABASE TABLE


KEY FIELDS

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.

There are three types of KEY fields which are:

a) Primary key
b) Composite key
c) Foreign key

KEY FIELDS EXPLAINED

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.

FOREIGN KEY ILLUSTRATION

Consider the structure of these two tables:

Table CUSTOMER Table ORDERS


Column name Characteristic Column name Characteristics

Customer ID Primary key In Order ID Primary key

Last Name Order Date

First Name Customer ID Foreign Key

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.

Connection between database tables is termed as a RELATIONSHIP.

There are three main types of relationships in databases:-

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.

NOTE: This type of relationship is normally used in special circumstances.

ONE-TO-MANY RELATIONSHIP: This is when one record in one table relates to several records
in another table.

This is a very common type of relationship used in many databases.

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.

REFERENTIAL INTEGRITY ENFORCES THE FOLLOWING THREE RULES:

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

Text Text or combinations of text and numbers, such as addresses. Also


numbers that do not require calculations, such as phone numbers, part
numbers, or postal codes.

Memo Lengthy text and numbers, such as notes or descriptions.

Number Numeric data to be used for mathematical calculations, except


calculations involving money (use Currency type).

Date/ Time Dates and times.

Currency Currency values. Use the Currency data type to prevent rounding off
during calculations.

AutoNumber Unique sequential (incrementing by 1) or random numbers automatically


inserted when a record is added.

Yes/No Fields that will contain only one of two values, such as Yes/No,
True/False, On/Off.

DATABASE SCHEMA

 A schema of a database is its structure described in a formal language supported by


the database management system (DBMS). OR
 Is a way of representing a database structure in a sheet of paper before implementing
it in the Database Manager.
 In a relational database the schema defines the tables, the fields, relationships and
other elements.
 Primary keys are represented by solid underline while foreign keys are represented by
a dotted underline.
 Field names are normally enclosed in brackets, preceded by a table name.

SAMPLE DATABASE SCHEMA

 You can design a schema by using drawings or just text. The example below shows a
database schema written in text.

Database name: Book Library

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.

NOTE: Normal fields and the key fields are indicated.

for Book Library Database

MODULE NO 2.0: OFFICE APPLICATION


UNIT NO 2.3: DATABASE APPLICATION
ELEMENT NO 2.3.2: CREATING TABLES
Tables contain all the data in a database and are the fundamental objects for your work in
Access. There are different ways to create a table in Access, including Design View and
entering the fields and records for a table directly in Datasheet view.

CREATING A TABLE IN DESIGN VIEW


Creating a table in design view involves entering the field names and defining the properties
for the fields, specifying a primary key for the table, and saving the table structure.
 Open any database
 Choose the Table Design command in the Tables group on the Create tab
 In the first cell in the first row, enter a field name
 Press [Tab]
 Choose a Data Type from the Data Type drop-down list
 Press [Tab] twice
 Enter your next field name
 Continue with steps 4 through 7 until all fields have been entered and properly
assigned a data type
 Click the Save command on the Quick Access Toolbar
 Enter a table name
 Click OK

CREATING A TABLE IN DATASHEET VIEW


 Click the create tab on the Ribbon.
 In the Tables group, click the Table button.
 Accept the default ID primary key field with the AutoNumber data type, or rename
the field and change its data type, if necessary.
 Double-click the Add New Field column heading, and then type the name for the field
you are adding to the table.
 Press the Tab key or the Enter key.
 Add all the fields to your table by typing the field names in the column headings and
pressing the Tab key or the Enter key to move to the next column.
 In the first row below the field names, enter the value of each field in the first record,
pressing the Tab key or the Enter key to move from field to field.
 After entering the value for the last field in the first record, press the Tab key or the
Enter key to move to the next row, and then enter the values for the next record.
Continue this process until you have entered all the records for the table.
 Click the Save button on the Quick Access Toolbar, enter a name for the table, and
then click OK button.

GUIDELINES FOR NAMING FIELDS


Keep the following guidelines in mind when you name the fields:
 A field name can consist of up to 64 characters, including letters, numbers, spaces, and
special characters, except for a period (.), exclamation mark (!), accent grave(`), and
square brackets([]).
 A field name cannot begin with a space.
 Capitalize the first letter of each word in the field name so it is clear which words are
parts of the name.
 Use concise field names that are easy to remember and reference, and that won’t take
up a lot of space in the table datasheet.
 Use standard abbreviations, such as Num for Number, Amt for Amount, and Qty for
Quantity.
 Give fields descriptive names so that you can easily identify them when you view or
edit records.
 Different DBMSs and some organizations have specific rules for naming fields. For
example, many experienced database users do not include spaces in field names for
ease of use when working with fields and other objects to perform more complex
tasks, such as programming.

RENAMING THE DAFAULT PRIMARY KEY FIELD


As noted earlier, Access provides the ID field as a default primary key for a new table you
create in Datasheet view.

To rename the ID field do the following:


1. Right-click the ID column heading to display the shortcut menu, and then click Rename
Column. The column heading ID is selected, so that whatever text you type will replace
it.
2. Type a new field name and then press the Enter key. The column heading changes to a
new name and the insertion point moves to the row below the heading.

CHANGING THE DATA TYPE OF THE DEFAULT PRIMARY KEY FIELD


The data type determines what field values you can enter for the field. In this case, the
AutoNumber data type is displayed. Access assigns the AutoNumber data type to the default
primary key field because the AutoNumber data type automatically inserts a unique number
in this field for every record. Therefore, it can serve as the primary key for any table you
create.

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.

DEFINING RELATIONSHIP BETWEEN TWO TABLES


When two tables have a common field, you can define a relationship between them in a
relationships window.

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.

To enter the first record in a table:-


 Click in the first row for the first field, type field value and then press the Tab key.
Access adds the field value and moves the insertion point to the right.

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

1. A (n) _______________ is a single characteristic of a person, place, object, event, or


idea.
2. You connect the records in two separate tables through a (n) ____________ that
appears in both tables.
3. The_______________, whose values uniquely identify each record in a table, is called
a (n) ________________ when it is placed in a second table to form a relationship
between the two tables.
4. The ________________ is a database object that allows to extract records from a
table/tables based on a certain criteria.
5. Which field does Access create, by default, as the primary key field for all new
datasheets?
6. Explain briefly the primary purpose of a database.
7. What is Microsoft Access?
MODULE 2.0: OFFICE APPLICATION
UNIT 2.3: DATABASE APPLICATION
ELEMENT 2.3.3: CREATING QUERIES
A query is a database object used to extract information from the database based on criteria
that you define. Or it is a question you ask about the data stored in a database.

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:

 Display selected fields and records from a table.


 Sort records.
 Perform calculations.
 Generate data for forms, reports, and other queries.
 Update data in the tables in a database.
 Find and display data from two or more tables.

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.

TO CREATE A SIMPLE QUERY BY USING A QUERY WIZARD DO THE FOLLOWING:


1. Click the create Tab on the Ribbon. The create tab provides options for creating
database objects (tables, forms, reports, queries, and so on).
2. In the Other group on the Create tab, click the Query Wizard button. The New Query
dialog box opens.
3. Make sure Simple Query Wizard is selected, and then click the OK button. The first
Simple Query Wizard dialog box opens.
4. Select a table in the Tables/Queries box and all fields in that table are listed in the
Available Fields list box.
5. You need to select fields from the Available Fields list box to include them in the query.
To select a field one at a time, click a field and then click the > button. The selected
fields then moves to the right (Selected Fields box). To select all the fields, click the >>
button. If you change your mind or make mistake use the < or << button to remove the
selected fields.
6. Click next button(s) and make your selections or accept the wizard’s defaults for the
remaining options by clicking Finish button.
7. You can use the suggested name for the query or click at the end of the suggested
name, use backspace key to delete the name and type a new one.
8. Click Finish button to complete the query. Access displays the query results in
Datasheet view, similar to a table datasheet showing fields and records only for those
fields and records you want to see, as determined by the query specifications you
select.
NOTE: The query results are not stored in a database; however, the query design is stored as
part of the database with the name you specified.

A QUERY EXAMPLE

Consider you have the following database:

Database name: Book Library

Tables: Book (Book ID, Title, Year, Pages, Author ID,)

Author (Author ID, First Name, Last Name, Nationality)

Borrower (Student ID, First Name, Last Name)

Book_Borrower (StudentID, BookID, BorrowDate, ReturnDate, Returned)

You may ask from the database questions like:

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.

2. Which books were borrowed but not returned?

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 create a form using the Form tool:


1. The table or other database object you are using as the basis for the form must either
be open or selected in the Navigation Pane.
2. In the Forms group on the Create tab, click the Form button. The Form tool creates a
simple form showing every field in the table or query selected. Access assigns a name
similar to that of an object is created with.

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

• A report is a formatted printout of the contents of one or more tables in a database.


• Reports allow you to view and present data from your database in a printed form.
• Microsoft Access offers several styles and formats for reports, so you can create a
customized document to suit your needs.

CREATING A SIMPLE REPORT


You can create design your own report, use report wizard or use the Report tool to create a
simple report with one mouse click.

To create a simple report using the Report tool:


1. With the table open in Datasheet view, click the Create tab on the Ribbon.
2. In the Reports group on the Create tab, click the Report button. The report tool creates
a simple report showing every field in the selected table and assigns the same table of
the table.

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.

You might also like