Topic 5 Database Development
Topic 5 Database Development
DevelopmentI
LEARNING OUTCOMES
At the end of this topic, you should be able to:
1. Apply Microsoft Access effectively to produce a complete
database;
2. Develop a query using the Query By Example (QBE); and
3. Produce forms and reports through Microsoft Access.
X INTRODUCTION
In this topic, you will learn the basic development of a simple database. The
development tool used is Microsoft Access, one of the Database Management
Systems applied in personal computers. Among the available Microsoft Access
functions are storage, isolation and retrieval of data for various applications. This
software is equipped with tools to create databases, tables, forms, reports and
queries. Microsoft Access is based on stand-alone or multiple user networks. For
this topic, each step involved in the use of Microsoft Access will be explained. As
such, it will be more helpful if you could read this module in front of a personal
computer with the Microsoft Access programme running.
Query
With Access, it easy for users to submit a complex query regarding the data
inside the database. The result is generated in a relatively short time.
Form
Users can create an interesting and useful form to display and update the
data.
Report
Access provides a feature that allows users to produce a sophisticated
report to represent data in a clear and concise way.
Web Supporting
Access allows users to save objects (form, table and others) into HTML
format in order to view them using a browser. Users also can create a page
for achieving real-time data using the Internet.
Before you start to create a database using Microsoft Access, it would be better if
you could recall the concept of database which you briefly learnt the in Analysis
and Data Modeling course.
Creating databases;
Adding, changing, and deleting data in databases;
Sorting data in databases;
Retrieving data from databases; and
Creating forms and reports using data in the databases.
The database containing of two tables which are mentorees and mentor table.
The rows of table are named as record. Record is containing information about
people, product, event and others. Mentorees table for example containing all
records of each mentorees.
Meanwhile the columns of the table are named as fields. Each fields containing
the specific information of the record. In mentorees table, the field of
MatricNumber refers to the matric number of mentorees (student). In this case,
MatricNumber is the primary key which refers to the field that can differentiate
all record uniquely.
Based on this dialogue box, we are able to create or open the current database.
When a new database is created, we can choose to start with a black object and
begin from start or use the Access Wizard to build the database. Access Wizard is
the expert in a database system that poses certain question to users about the
objects required such as the database and it constructs the object based on the
answers replied.
This database stores all the components of a database structure. The Windows
database is the centre for us to build and use any objects in the database. Objects
of database components are tables, queries, forms, reports, macros and modules.
When one component is chosen, all element names in that component are shown
in Windows. In Figure 5.2, components to create tables are presented. There are
three keys on the left side of the Windows.
Let us focus on the creation of tables within the MentorMentoree database in the
following section.
TOPIC 5 DATABASE DEVELOPMENT I W 67
In this section, we shall build mentoree table with the correct command through
Design View. The computer screen should appear as shown in Figure 5.4.
Figure 5.4: Design view for Mentoree table presenting the field property for Name
5.2.1 Field
First, we have to determine attributes for each table. In Access, the attribute is
called Field and domain is known as type. We need to fulfill the information
required in the Table Design View for each field in Mentoree table such as name,
type and description. Figure 5.4 shows the creation of the Mentoree table in
Design View. Microsoft Access supports various types of data to store various
types of information. For each field in the Mentoree table, we need to choose the
suitable type of data and ensure the storage mechanism is effective. In the
68 X TOPIC 5 DATABASE DEVELOPMENT I
example shown, most fields are presented as Text including Name, programme,
address and Mentor_ID. Matric_No is stated as Number.
Let us proceed to create the mentoree table by inserting several restrictions in the
table.
In the next subtopic, you will be taught about the field element in Microsoft
Access. This will assist you in determining how data is stored, managed or
presented.
Figure 5.5: The Field element for programme field of mentoree table in Design View
(e) Caption
Caption is a name given to an attribute when it surfaces in a report form. It
is used for providing explanations about the field name domain and serves
as valuable information to users through the captions on objects. For
example, if the 'Matric Number' is inserted in the Caption feature as
Field_No, the tuple named 'Matric_Number' will be presented in the table
within the Datasheet and not the 'Matric_No; field.
70 X TOPIC 5 DATABASE DEVELOPMENT I
When the data input does not fulfill the Validation Rule the Validation Text
feature, warning messages are presented to users. The Validation Rule
determines the allowed value range for data domain or numeric. The rule
lessens the possibility of errors occurring when data is inserted into the
table.
(h) Required
The required domain is a domain with values in each record. If the feature
is fixed at 'Yes', we would need to insert the value inside the domain and
value must not remain zero or null. For example, each student must have a
matric number. As such, the matric_no in the mentoree table must consist
of values without any null value. The primary key field is to identify each
record uniquely. As such, the field of the primary key must not contain the
value null. When tables are created, the default value for each field,
including the primary key field, is set to 'Yes' according to the attribute
required.
(j) Index
This element is used to determine the field of index. This index expedites
the queries upon the index field and speeds up sorting and grouping
operations.
TOPIC 5 DATABASE DEVELOPMENT I W 71
SELF-CHECK 5.1
Create one new table name Mentor that containing all fields as below:
1. Name
2. Worker_Num
3. Faculty
4. Phone
5.4 RELATIONSHIP
The major error that always occur in developing database application systems is
that the entities are not modelled into a suitable relationship. The best practice is
for all entities and relationships to be placed in one table.
The advantage of this approach is that proper planning at the early stage of
application development Is not required. Nevertheless, this method also has
disadvantages such as waste of storage, difficulty to change data, difficulty to
remove data and also difficulty to add data.
When tables are created,they are not linked to other tables. To create this relation,
drag the field required to be linked from one table to another. In this example,
click the Worker_No field in the Mentor Table and drag it into Mentor_ID in the
Mentoree table.
The ratio between the Mentor and Mentoree table 1 to many (1:M) relations. In
other words, these relations show that one Mentor is responsible of several
Mentorees. Referential Integrity is regulated by using Enforce Referential
Integrity while the relation is linked as shown in Figure 5.7.
If the referential integrity is fixed and the user does not follow the regulation,
Microsoft Access will present the message and changes will not be allowed.
Examples of Referential Integrity are Cascade Update Related Fields and
Cascade Delete Related Record as shown in Figure 5.7. When Cascade Update
Related Fields is chosen, any changes in the primary key value in the parent table
will automatically be updated with the same value in the related tables. When
the Cascade Delete Related Record is chosen, deleting a particular record in the
parent table will also delete the same record in the child table (if it exists).
If you are reading this module with the Microsoft Access application in front of
you, your computer screen should display the same image as shown in Figure
5.7. To ensure that you truly understand this topic, answer the following
questions.
SELF-CHECK 5.2
Note: For further explanation with example, student can use the help
function in Microsoft Access for each field elements that you have
leant.
74 X TOPIC 5 DATABASE DEVELOPMENT I
To create a query using Access, there are two methods that can be used:
The important thing about the query is that it does not contain any data. A query
only arranges the data in database without changes in the table.
Through the Show Table window, you can choose the table to be used in queries.
For this example, choose the Mentoree Table and press the Add button. The
Mentoree table will appear. The Query window will be divided into two sections.
The upper section will be left blank initially and will be filled with information
on the schema table involved in query.
The lower section of the query consists of a table with field, table, show and
criteria rows. Assume that you want to present all data in Mentoree table; you
need to click on Field, click on the arrows pointing downwards and choose
which domain needs to be displayed. Then, click on the Show box as shown in
Figure 5.9. To execute the query, click on the exclamation sign in red on the
toolbar menu.
The result of this query is the records of the mentoree table that will displayed, as
shown in Figure 5.10. If we execute the same query to the mentor table, the result
will be as shown in Figure 5.11.
Based on the records from the mentoree table, we can fill up the schema as
shown in Figure 5.12 below, to search for the mentoree who registered for the BIT
or DIT programme. The result from this query can be found in Figure 5.13
Figure 5.12: Query Search for mentoree who registered for BIT or DIT programme
TOPIC 5 DATABASE DEVELOPMENT I W 77
Figure 5.13: The result of the query to find the mentoree who
registered for the BIT or DIT programme
Most of the created queries involve more than one table. Figure 5.14 shows a
schema to retrieve all mentorees with mentors who are lecturers in the faculty of
information technology. This is where the query would need the combination of
mentoree and mentor tables.
The result of this query can be found in Figure 5.15 as shown below:
78 X TOPIC 5 DATABASE DEVELOPMENT I
Figure 5.15: The result of the query to retrieve all mentorees with
mentors who are lecturers in the faculty of information technology
Some queries, the order of the query result give some important rule. Therefore,
Access provides a function that allows the result of query being arranged
according to the query requirement.
To arrange the displayed record, you can use the sort function. The field which
the record can be sorted is known as sort key. To sort record in Access, need to
state the type of sort in sort field as shown in Figure 5.16.
Figure 5.16: The query for displays Name, Matric_Number, Program and address that
need to be sorted by using the field of Program as ascending
Figure 5.16 refers to a query for displaying a record of student that be sorted by
Program field. The result of the query is shown in figure 5.17.
TOPIC 5 DATABASE DEVELOPMENT I W 79
Figure 5.17: The result of query for sorting the fields of Program as ascending
QBE can also use operational aggregate such as Sum, Avg, Min, Max and Count.
To implement this we need to add rows for the Total field by selecting the View-
Totals.
The following schema shows the query on number of mentorees for each mentor.
The attribute Name has a Group value in Total rows. This shows that the
attribute Name is used to collect rows in the mentoree table. The total field has
the operational Count in each group (Figure 5.18). Meanwhile, Figure 5.19 shows
the result of the query in Figure 5.18.
Figure 5.18: Query to count the number of mentorees for each mentor
80 X TOPIC 5 DATABASE DEVELOPMENT I
Figure 5.19: The result of the query that counts the number of mentorees for each mentor
The name of the query field should be different from any existing fields, while
the definition is an expression that can be evaluated by Access.
In the example given, the syntax for the query field is:
Mentoree: matric_no & name
TOPIC 5 DATABASE DEVELOPMENT I W 81
Figure 5.20 shows the process to create the query field. In this example,
expression involves the tow field which is field_no and name (from the mentoree
table). The operator symbol & is used to combine data from these two fields.
Similarly the symbol is used to create empty spaces between these two fields.
The result from this query is shown in Figure 5.21 below:
SELF-CHECK 5.3
2. FROM <table>
This component is to identify table (or tables) that involved in the query.
4. ; <semi colon>
All query of SQL must end by semi colon. If you are forgotten to include it,
Access will put it automatically.
84 X TOPIC 5 DATABASE DEVELOPMENT I
An example to shows the usage of the SQL as shown in figure 5.23. This figure
shows the SQL command that need to find the names of mentorees whose are
under supervision Mentor who have ID = P00001.
Figure 5.23: SQL command to find the names of mentorees whose are under supervision
Mentor with ID =P00001
The result of this query as shown in figure 5.24. The result displays the name list
of Mentorees whose are under supervision Mentor with ID =P00001.
TOPIC 5 DATABASE DEVELOPMENT I W 85
For AND criteria, each criterion certainly fulfilled to enable multiple criteria
accurate. For example, AND criteria enable user to find name list of mentorees
whose are under supervision Mentor with ID =P00001 and the mentorees also
registered BITM program. The SQL command to fulfill those criteria is shown in
figure 5.25 below:
Figure 5.25: SQL command to retrieve the names of mentorees whose are under
supervision Mentor with ID =P00001 and registered BITM program
The result that acquired from SQL command that was given from figure 5.25 is
shown as figure 5.26.
86 X TOPIC 5 DATABASE DEVELOPMENT I
Figure 5.26: The result of SQL command to find the names of mentorees whose are under
supervision Mentor with ID =P00001 and registered BITM program
Difference with AND criteria, OR criteria requires only one criteria to fulfilled to
enable the result of the query are accurate. This example is to retrieve the name
of mentorees whose are registered in BITM program and under supervision
mentor which either ID P00001 or P00003. The SQL command is shown in Figure
5.27.
Figure 5.27: SQL command to retrieve the names of mentorees whose are registered in
BITM program and under supervision mentor which either ID P00001 or P00003
TOPIC 5 DATABASE DEVELOPMENT I W 87
The result of the query is the name list of mentorees that fulfilled one of those
criteria will be displayed as shown in Figure 5.28.
Figure 5.28: The result of SQL command to find the names of mentorees whose are
registered in BITM program and under supervision mentor which either ID P00001 or
P00003
SELF-CHECK 5.4
Microsoft Access
Database