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

Mock Final Exam Paper

1804ICT – Data Management


7003ICT – Database Management
Time: 60 min Total Marks: 30
1. Answer briefly of the following questions:
a) What is meant by a ‘deadlock’? [1 mark]

Ans: A deadlock occurs when two users are trying to lock multiple parts of the database and each has
locked some of what they want to lock but cannot complete their lock because the next part is locked
by the other user. Also known as deadly embrace.

b) What is a ‘transaction’? Give an example. [2 marks]

Ans: A single transaction is a collection of two or more SQL statements. For example, a sales transaction
could include:
▪ Update customer’s account
▪ Adjust inventory
▪ Update seller’s accounts receivable
▪ Update reward cards, etc.
All parts need to be successfully completed – otherwise data integrity problems introduced.

2. Design a logical ERD for the following case study. Use the Crow’s Foot notations in your designed
ERD. [7 mark]
Case study:
• Acme Pty Ltd is made up of a number of departments that manage none or more projects.
Each project belongs to a department.
• Each department employs a number of employees. Each employee works in one department.
• A team of employees work on each project.
• Some employees may not be assigned to any project yet and a new project may not have any
team assigned to it.
• One of the team members supervises the other team members on the project.

In particular, in the ERD you need to show:


a) All entities with their attributes, including PK and FK attributes [4 marks]
b) Relationship (with name) between entities, and [1.5 marks]
c) Cardinality and modality between entities. [1.5 marks]
Ans:

Note: Some employees may not work in any project, so they are neither supervising nor being
supervised by other employees. So, in supervision (self) relationship both sides are optional.

3. For the table BOOKAUTHOR below you are given the following functional dependencies.

BOOKAUTHOR (ISBN, BookTitle, Author_Num, LastName, Publisher, Royalty, Edition)

Functional dependencies: [1 mark]

a) ISBN → BookTitle, Publisher, Edition


b) Author_Num → LastName
c) BookTitle → Publisher
d) {ISBN, Author_Num} → BookTitle, LastName, Publisher, Royalty, Edition

Write the types of functional dependencies shown in (a) to (d) above.

Also, decompose the table to the third normal from (3NF).


Ans:

a) Partial
b) Partial
c) Transitive
d) Full

The table is already in 1NF as the PK is identified. To convert to 2NF we remove the partial
dependencies: [2 marks]

BOOKAUTHOR (ISBN, Author_Num, Royalty) in 3NF

BOOK (ISBN, BookTitle, Publisher, Edition) in 2NF

AUTHOR (Author_Num, LastName) in 3NF

BOOK table above has a transitive dependency (BookTitle → Publisher), so it needs to be removed to
take the table to 3NF: [1 mark]

BOOK (ISBN, BookTitle, Edition) in 3NF

PUBLISHER (BookTitle, Publisher) in 3NF

So, all tables in 3NF are: [1 mark]

BOOKAUTHOR (ISBN, Author_Num, Royalty)

AUTHOR (Author_Num, LastName)

BOOK (ISBN, BookTitle, Edition)

PUBLISHER (BookTitle, Publisher)

Alternative solution using the dependency diagrams:


(If the students want to solve using the dependency diagram, this is fine.)

1NF:

The table is already in 1NF as the PK is identified.

Dependency diagram:
Conversion to 2NF:

Remove 2 partial dependencies:

Conversion to 3NF:

The first table in 2NF above has a transitive dependency. So, we remove this dependency.
4. The book database has the following Relation Schema: [10 marks]
Author (AuthorNum, AuthorLast, AuthorFirst)
Publisher (PublisherCode, PublisherName, City)
Book (BookCode, Title, PublisherCode, DateFirstPublished, Type, Price, Paperback)
Branch (BranchNum, BranchName, BranchLocation, City, NumEmployees)
Inventory (BookCode, BranchNum, OnHand)
Wrote (BookCode, AuthorNum, Sequence)

Using the above schema, write MySQL statements for the following queries (a to b):
a) Find the books whose prices are more than the average books price. [3 marks]

Ans:
SELECT *
FROM book AS B
WHERE B.Price > (SELECT AVG(price));

b) List publisher names and their locations for those studios that have the letter r in the third
position of their names. [2 marks]

Ans:
SELECT *
FROM publisher
WHERE PublisherName LIKE '__r%';

Using the above schema, complete the MySQL statements for the following queries (c to e):
c) For each branch, show the branch id and total number of books on hand if the total number on
hand is less than 25. [1.5 marks]

SELECT BranchNum, __________ AS 'No of books on hand'


FROM Inventory
GROUP BY __________
HAVING ____________;

Ans:
Sum(OnHand)
BranchNum
Sum(Onhand) < 25

d) List author names in order of their sequence in the book Treasure Chests. Show author
numbers, full names, and the sequence. [2.0 marks]

SELECT A.AuthorNum, ________(AuthorFirst, ' ', AuthorLast) AS 'Full name',


W.Sequence
FROM Author As A, wrote as W, book AS B
WHERE A.AuthorNum = W.AuthorNum
AND ______________________
AND ______________________
ORDER BY_____________;

Ans:
CONCAT
W.BookCode = B.BookCode
B.Title = 'Treasure Chests'
W.Sequence

e) Find the books which are of the same types as the books Beloved or The Edge.[1.5 marks]

SELECT *
FROM _________
WHERE Type = ____ (SELECT B.Type
FROM book AS B
WHERE B.Title = 'Beloved'
____ B.Title = 'The Edge');

Ans:
BOOK
ANY
OR

You might also like