MS Access 2016: This Tutorial Has Been Adopted From Microsoft Website and The Book Above With Modification

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

COS10082 Applied Analytics in Business Lab 5

MS Access 2016
In this lab, you will:
learn to design Databases with MS Access 2016
References:

Joyce Cox and Joan Lambert, Microsoft Access 2013 Step by Step
(Microsoft Press 2013)
This Tutorial has been adopted from Microsoft website and the book above
with modification.

PART I: Creating Databases and Tables

Consider the following Database which gives information about clients and
property rental.

Source: Conolly & Begg Database System text book

This database has four tables (Clients, Rental PropertyForRent and Owner).
Lets implement this database in MS Access 2016.

Open MS Access 2016


Click on Blank Desktop Database
Browse to your folder and name the file (ClientRental.accdb)
Click on Create

Page 1 of 8
COS10082 Applied Analytics in Business Lab 5

A default Table1 will be created (can be seen at the left side of Access) with
one attribute ID (which is created to be the unique identifier for the table
Primary key). You will notice that Table Tools are activated since we are now
working with tables.

On the Table Tool -> Fields, go to View and click on Design view, you will be
asked to rename Table1, rename it to Client
The fields of the table will be shown, so, rename ID to ClientNo and change
the data type to the most appropriate data type to store the data given.

Add the second field of the table Client and select Short text as the data
type.

Page 2 of 8
COS10082 Applied Analytics in Business Lab 5

Right-click on the key next to the left of the ClientNo field and make sure
Primary key is selected.
Go back to Data Sheet View, and insert the data given in the Client Table.
Now, lets create the Rental Table and insert the data

Go to Create tab and click on Table (a new table will be created).


Go to home tab and in the View, click on Design View
Rename the table to Rental and add the fields with their data type. Make
sure that both (ClientNo & PropertyNo) is the Primary key (why?)

Add the table data

Now, lets Repeat the above steps to create PropertyForRent and Owner
tables, and insert their data.

Page 3 of 8
COS10082 Applied Analytics in Business Lab 5

PART II: Defining Relationships between Tables

Close all tables (using the close icon at the right side of each table)
On the Database Tools tab, in the Relationships group, click the Relationships
button to open the Show Table dialog box.
Add all tables (select a table name and click add) then click on close

We have four tables, and their fields are listed. By looking at Client and Rental,
we can notice that both have one common field (ClientNo) which indicates
that these two table have a direct relationship. The same thing goes for Owner
and PropertyForRent as well as PropertyForRent and Rental.

Lets define the relationship between Client and Rental:

On the Client Table, click and hold on the ClientNo and drag it to the
ClientNo field on Rental table.
The Edit Relationships window will appear as follows:

Select the Enforce Referential Integrity check box, and then click Create

A one-to-many relationship will be created between the two tables. (you can
re-arrange the tables by click and drag the table to another location.

Page 4 of 8
COS10082 Applied Analytics in Business Lab 5

Repeat the above steps to define the other relationships.


You should get the following:

PART III: Creating Simple Queries

Now, we will learn on how to retrieve information from either one or multiple
tables.
Using Query Wizard

Lets design a query that will display the Client Name and the Address of the
Property they have rented.

- The two columns, are available in the Client table(Client Name) and
ProperyForRent(PAddress). But both have a relationship with the Rental
table.
On Create tab -> Queries Group, click on Query Wizard
Select Simple Query Wizard, then click OK
The following Simple Query Wizard window will appear.

Select the Table from Tables/Queries drop down menu and then select the
field then click on to transform the column to Selected Fields.

Page 5 of 8
COS10082 Applied Analytics in Business Lab 5

You should get the following:

Click on Next
On the following dialogue, tick on detail, then click Next
Give the Query a title. Then click Finish.
You should get the following:

Page 6 of 8
COS10082 Applied Analytics in Business Lab 5

Using Query Design

Lets design a query that displays the Client Name, Property No, Rental start
date, rental end date and the owner name.

- This query involves Client Table, Rental Table, and Owner Table.
On Create tab -> Queries Group, click on Query Design
On the Show table window, select the all tables
You should see this

Now, lets select the fields that we are interested with using the Field drop down
menu that appears at the bottom of the above picture.

Select, CName from Client, PropertyNo from Rental, RentStart from Rental,
RentFinish from Rental and OName from Owner.
To see the result, click on Run button.
You should get this

Page 7 of 8
COS10082 Applied Analytics in Business Lab 5

Lets only display the same columns but for rents that start after 15/7/2013
To do this,

Go to the design view


In the criteria row of the RentStart column, type
>15/7/2013

Click on Run

You can select / retrieve information based on multiple conditions and you
may use AND or OR. If you want to use AND for multiple conditions use them in
the same row; if OR, then write the condition on the or: row.

Your Turn
Develop the following Library Database in Access. Add some data

What are the foreign keys? And in which tables?


Create the following Queries

List the book titles and their dateOut.


List book titles and name of borrower
Count how many books have been loaned.
Display books that have been published in one year (select the year
based on your data enteries)

Page 8 of 8

You might also like