Solutions to HW#4

Transcription

Solutions to HW#4
HW#4
CMPSC 430
1. Hogwarts ERD
Notes:
•
•
•
•
•
•
Student participation in Assigned must be total and to one; House participation in Assigned is partial
House participation in Heads must be total and to 1; Professor participation should be partial and to 1
Student participation in EnrolledIn must be total and to many; Course participation is partial
Professor participation in Teaches should be partial, as should Course participation (if total, ok)
Equipment should be a multivalued attribute
Spell should be a weak entity with total participation in Has; Course can be either partial or total
participation in the Has relationship
2. Employee: SSN, FName, MInit, LName, Salary, Address, Gender, DOB, DName, DNumber, [DLocation]
Department: DName, DNumber, DLocation (DLocation does not have to be part of primary key)
Project: PName, PNumber, PLocation, DName, DNumber, [DLocation]
Dependent: SSN, Name, Relationship, Gender, DOB
Supervision: SSSN, ESSN (the supervisee’s SSN must be the key)
Manages: SSN, Name, Number, StartDate or SSN, Name, Number, StartDate
Works_On: SSN, Name, Number, Hours
•
•
•
•
•
Works_For relation not necessary because it is many-to-1 and participation of the entity on the “many” side
(Employee) is total. So we can add columns DName, DNumber, DLocation as the primary key attributes of
the “to one” side (department) to Employee and get rid of the relationship set Works_For. Same for Controls
(add DName, DNumber, DLocation to Project)
Department has location added because it is a multivalued attributed and if all attributes of the entity set,
other than the mv attribute, are primary key attributes, then we need only the table for the mv attribute.
NumberOfEmployees is derived, so it should not be listed as an attribute of Department
In Supervision, need to give unique names to the SSNs (one from supervisor, one from employee)
Could get rid of Manages and move SSN and StartDate to Department (but was not something we covered in
class)
Could also have
Employee: SSN, FName, MInit, LName, Salary, Address, Gender, DOB, DName, DNumber
Department: DName, DNumber, SSN, StartDate
Project: PName, PNumber, PLocation, DName, DNumber
Dependent: SSN, Name, Relationship, Gender, DOB
Location: Name, Number, Location
Supervision: SSSN, ESSN
Works_On: SSN, Name, Number, Hours