Uploaded by micheal king

PAST PAPER ASSIGNMENT

advertisement
PAST PAPER ASSIGNMENT
Kyle M. King
University of the West Indies (Five Island Campus)
COMP3330: Database Systems 1
Dr. S. Leacock
31/12/23
Question 1
Question 2
Consider the relational schema R (B, 0, S, Q, I, D) and the functional dependencies S → D, I → B, IS → Q,
and B → 0.
(a) Show that IS is the key for R:
To prove that IS is the key for R, we need to show that it satisfies two conditions:
▪
Uniqueness: IS uniquely identifies each tuple in R.
▪
Irreducibility: No subset of IS has the uniqueness property.
Given the functional dependencies: S → D, I → B, IS → Q, B → O.
Uniqueness:
▪
IS uniquely identifies each tuple because no other combination of attributes in R has the
same closure as IS.
▪
For any subset of IS, adding any attribute will increase the closure and result in a
different set of attributes.
Irreducibility:
▪
No proper subset of IS has the uniqueness property.
▪
Removing any attribute from IS will result in a non-unique closure.
▪
Therefore, IS is the key for R.
(b) Convert R to an equivalent set of 3NF relations:
▪
Since R is not in 3NF, we need to decompose it while preserving functional
dependencies. Here's the decomposition:
Given functional dependencies: S → D, I → B, IS → Q, B → O.
Create two relations:
▪
Relation 1 (R1): {I, B}
▪
Relation 2 (R2): {S, D, I, S}
Explanation:
▪
R1 has the key I, and the functional dependency I → B is preserved.
▪
R2 has the key IS, and the functional dependencies S → D and IS → Q are preserved.
Question 3
Consider the following set of relations, with primary keys underlined:
LECTURER (LEC-ID, LEC-NAME, PHONE, DEPT)
REQUESTS (LEC-ID, BOOK-ID, QTY, DATE)
BOOK (BOOK-ID, TITLE, AUTHOR, COST, SUPPLIER)
(Assume that QTY and COST are of type numeric, DATE is of type date, and all other attributes are of
type character.
Write syntactically correct MySQL commands to answer the following queries:
(a) Find the name and phone number of each lecturer requesting the book with ID# 123.
SELECT LEC_NAME, PHONE
FROM LECTURER
WHERE LEC_ID IN (
SELECT LEC_ID
FROM REQUESTS
WHERE BOOK_ID = 123
);
(b) For each lecturer find the lecturer's id, name, and title of each book that he/she requests.
SELECT LEC_ID, LEC_NAME, TITLE
FROM LECTURER
JOIN REQUESTS ON LECTURER.LEC_ID = REQUESTS.LEC_ID
JOIN BOOK ON REQUESTS.BOOK_ID = BOOK.BOOK_ID;
(b) Increase, by 10%, the cost of books supplied by (supplier) Prentice-Hall'.
UPDATE BOOK
SET COST = COST * 1.1
WHERE SUPPLIER = 'Prentice-Hall';
Question 4
You are required to design a database to keep data about university students (attributes:
STUNAME, MAJOR, CREDITS), their academic advisors (attributes: LECTID, LECTNAME, DEPT, OFFICE),
the clubs (attributes: CLUBNAME, PRESIDENT, VICE-PRES, MEETING-ROOM) they belong to, the
moderator (a lecturer) of the club, and the activities (attributes: ACTIVITY-NAME, DATE, TIME, PLACE)
that the clubs sponsor. Assume that each student is assigned one academic advisor, but an advisor
counsel many students. Each student can belong to any number of clubs, and the clubs can sponsor any
number of activities. Each activity is sponsored by only one club, but there may be several activities
scheduled for one day.
(a) Draw an Entity-Relationship Diagram (ERD) for the above database, stating all semantic
assumptions that you make. Be sure to identify weak entity sets, if any.
Figure 1 Entity relationship diagram
•
Semantic assumptions:
o
o
o
o
•
Student-Advisor Assignment:
▪
Each student is assigned exactly one academic advisor.
▪
An advisor can counsel multiple students.
Club-Advisor Assignment:
▪
Each club has one lecturer serving as a moderator.
▪
A lecturer can moderate multiple clubs.
Student-Club Association:
▪
Students can choose to join multiple clubs.
▪
Clubs can have various students as members.
Club-Activity Sponsoring:
▪
Clubs can organize multiple activities.
▪
Each activity is associated with only one club.
Weak Entity Sets:
o
There are no weak entity sets in the scenario. All entities seem to have strong identities
and are directly described by their attributes.
(b) Convert the ERD in (a) to an equivalent relational schema in third normal form (3NF). Explain your
answer.
Figure 2 Relational schema
Download