Sei sulla pagina 1di 8

MACQUARIE UNIVERSITY

Faculty of Science and Engineering


Department of Computing

ISYS224 Database Systems 2017 (Semester 2)

Assignment 2

Database Programming and Implementation (worth 20%)

Due: 11:55 pm, Friday, Nov 3, 2017 (Week 12)

Plagiarism
Plagiarism is where you use the work of another person and present it as your
own. This is akin to stealing and is not permitted. If you are caught encouraging,
assisting or committing plagiarism, you will receive negative marks for the work
and possibly suspension from the unit.

The Universitys plagiarism rules are at:

Macquarie Academic Honesty Policy

It is in your interests to familiarise yourself with these rules.

Important Note:

You are required to submit your assignment on iLearn by the due date.
The background knowledge for this assignment is given in the textbook(s), lectures, any other
components of the unit, and in the readings provided on iLearn. However, some parts of the
assignments may not be answered without prior independent research and searching for other
sources of information.

This assignment will be marked out of 20 and will contribute 20% towards your final grade.

1 Problem Domain
The problem domain is the same as that you came across earlier in Assignment 1. For
convenience its description is reproduced below. Also, following the domain description, is
provided a simplified relational data model for the problem domain.

Domain Description

This case study deals with a system used by a Book Shop Chain, known as Sydney Book House
(SBH). The information to be stored in the system includes four major categories of data: branch
information about SBH, author information, book information, and publisher records.
Information about employees of SBH and other relevant data are also stored in the system.

A. Branch Information: SBH has several branches all over Sydney. The system shall contain
a branch name, an ID number, address and number of employees working at that branch.

B. Author Information: The system shall contain a list of author identifiers along with author
name and author email address.

C. Book Information: The system shall contain a list of unique book identifiers including book
title, book type (e.g. fiction, history, educational), price of that book and whether it is paperback
or not (yes/no). The following business rules are operative:

1. Each book is published by a publisher who is listed in the system. A publisher may or
may not publish any books.

2. Each book must be written by at least one author. There may exist multiple authors for
a book. In this case, the author sequence must be maintained as in the cover page of the
book. Of course, an author can write many books or she might be waiting to publish her
first book.

3. In addition, the system must keep track of the number of copies available for each book
per branch of SBH. A branch may have many books in its store (possibly none).

D. Publisher Information: The system shall contain information about publishers. Each
publisher must have an identifier which is a unique code of three alphanumeric characters,
publisher name, city and contact number. As mentioned earlier, a publisher may publish many
books (possibly none).

E. Employee Information: The system shall contain a record of all employees who work at
SBH. Each employee has a unique eight alphanumeric character long identifier, name,
employee type (e.g. permanent, contractual, casual etc.). Each employee must have a supervisor
to whom he/she reports to. Supervisors are also employee of SBH.

F. Working Shift Information: The system shall contain a list of working shift identifiers
including the week day (Monday-Sunday), start time, end time and type of duty (e.g. cleaning,
sales, security). The management maintains a duty roster for employees specifying who works
on which working shift each week. Since employees prefer to have weekends off, SBH has a
policy that no employee is allocated working shift for consecutive weekends.

G. Auxiliary Information: Some branches of SBH are located at more important locations in
the city and attract more customers than others. Therefore, the management has decided that
employees can be rostered to work at different branches so that workload of each employees
will be more balanced. However, the standard hours of work for an employee are 35 hours a
week. Also, no employee is scheduled to work in more than one branch in a given week.
Figure 1 : Relational Data Model
2 Task Specifications

Task One [1 mark]


a. Create the tables listed in the relational data model as shown in Figure 1. You may
choose to run the sample script (sample_script.sql) provided in the 'Assignment 2'
folder. Alternatively, you might want to use your own script, but make sure it aligns
with the model provided as Figure 1 above.

b. Add a new table called DutyRosterHistory to the database in order to log the weekly
roster data for all the employees. The relational schema of the table is given as:
DutyRosterHistory (EmployeeID, BranchID, WorkingShiftID, WeekStarting)
Primary Key: EmployeeID, WorkingShiftID, BranchID, WeekStarting
Foreign Key: EmployeeID refers to EmployeeID in Employee;
BranchID refers to BranchID in Branch;
WorkingShiftID refers to WorkingShiftID in WorkingShift;

Note: [In the above schema, the column, WeekStarting is expected to set as DATE type].

c. Populate some of the tables in the database by running the script (populate.sql) provided
in the Assignment 2 folder.

Task Two [4 marks]

Write a stored procedure that updates the weekly duty roster for an employee and allocates
him/her a maximum of 5 work shifts in a given branch. To update the roster, the procedure
ensures that:

i. The employee has an existing roster allocated to her/him. In case there is no existing
roster for a given employee, the procedure doesnt update the roster, rather prints an
appropriate error message.

ii. The day of current roster is shifted by one day in the updated roster. For instance, if the
current roster for an employee shows work shifts from Monday to Friday, then the
updated roster will allocate work shifts from Tuesday to Saturday. For simplicity, we
will assume that the type and number of work shifts allocated to an employee remain
same from week to week unless an exception occurs such as overallocation. However,
the manager may wish to add any extra work shifts to an employee manually.

iii. A warning message is displayed in case the allocated hours of work for an employee
exceeds the standard hours of work (35 hours per week).

Task Three [4 marks]


Write a database trigger to enforce the following business rules in the sample Bookshop
database as shown in Figure 1. Make sure that appropriate and informative feedback is given to
the user if the relevant insertion or update fails.

i. Sydney Book House updates the weekly roster for employees on each Friday for the
following week starting form Monday. It also keeps record of all employee roster data
in a separate table named as DutyRosterHistory; that is when a roster of an employee
is updated, a corresponding row is inserted into the DutyRosterHistory table, where
the column, WeekStarting is the following Monday. For example, if a roster for an
employee is updated on Friday, Oct 20, 2017, the value of the column, WeekStarting
will be Oct 23. 2017 (the following Monday)

ii. SBH also emphasizes on fairness to employees, and has a policy that no employee is
allocated working shift on consecutive weekends. For example, if Franz Kafkas current
roster shows work shift on either Saturday or Sunday or on both days, he cannot have
any work shift on weekends in the updated roster.

Task Four [2 marks]


This task involves testing all the code developed in Task Two and Task Three.

a. Insert the records into DutyRoster table as shown in Table1. Note that you may need
to check appropriate data into some additional tables because of the referential integrity
constraints.

b. You are required to test the following scenarios and show all the records in the tables
(DutyRoster and DutyRosterHistory) before and after testing.
1. Update the roster for an employee with Employee ID 1013 to allocate work shifts in
Branch 101.
2. Update the roster for an employee with Employee ID 1001 to allocate work shifts in
Branch 103.

Table 1: Sample Data for DutyRoster table

EmployeeID BranchID WorkingShiftID

1001 101 6001

1001 101 6002

1001 101 6003

1001 101 6007

1001 101 6008

c. Place all the MySQL code from the above tasks (Tasks 1, 2, and 3) both in your .sql file
as well as the .doc file. Also place all the test results in the .doc file.

Task Five [6 marks]

Consider the relational schema in Figure 1. The following SQL statement updates the duty type
of a particular work shift:

UPDATE WorkingShift
SET dutyType = 'Security'
WHERE WorkingShiftID = 5001;

a. Give an example of a query or statement that would conflict with the above UPDATE
statement if both the statements are run at the same time (when run concurrently).
Explain what could go wrong, and how locking tuples would solve the problem.

b. Give an example of a query or statement that would conflict with the above UPDATE
statement (when run concurrently) and would lock the table exclusively (write lock) at
page/file level.

c. Briefly explain how the level of locking (field, record or page) may contribute to the
likelihood of deadlock occurring?
Task Six [3 marks]

The Book house, SBH has decided to purchase RAID arrays to store the database shown in
Figure 1. Which levels of RAID would you advise them to use and why?

3 Submissions
You are required to submit electronic copies of two files on iLearn.
a) You must submit a PDF document named A2_<FirstName>_<LastName>.pdf. You would
produce this pdf file from the word document you have prepared. This document will have
answers to all the six tasks (including the DDL scripts for inserting data, MySQL code and
test results). Make sure that the document you submit is easily readable, and nothing spills
over the margins.
b) Your DDL scripts and MySQL codes should also be submitted as part of a single SQL file
named A2_<FirstName>_<LastName>.sql.

The site for electronic submission is accessible from the unit website on iLearn.

Deadline for submission: Friday, 11:55 pm on 3rd November (Week 12).

Warning:

You must submit and name the files correctly.


If you changed your file after submission, you may re-submit your assignment again
before the submission deadline.

Marking Notes:

All assignments submitted late will automatically receive 0 marks without being marked (subject
to any special considerations).

Potrebbero piacerti anche