Uploaded by Ziming Wang

EXAM 1 REVIEW.doc

advertisement
COSC 3380
Name:
_________________
PS ID # ___
Exam 1 Review
Please open with OFFICE 365 WORD software. KEEP ALL
answers in WORD.
Before submitting please ALSO save as PDF.
Please attach your SET 1 Practice.doc and SET 1 Practice.pdf.
IT CLOSES AT 6:35 PM.
TempStaf
1
1. (15 points)
ERD Data Models (WHAT). TEXTUAL ANALYSIS IS A MUST!
Please use the PROPER ERD Language!
E1: Professors – A1: social security number
E1: Professors – A1: social security number
A university database contains information about professors (identified by social security
number, or SSN) and courses (identified by courseid). Professors teach courses; each of
E1: Course – A1: courseid
the following situations concerns the Teaches relationship set. For each situation, draw
and ER diagram that describes it (assuming no further constraints hold).
a. (5 pts) Professors can teach the same course in several semesters, and each offering
(1 E1: Professors “teaches” M E2:
must be recorded.
Course)
A1:social security
R1:teaches
E1:Professors
number
E1: Professors R1: teaches E2: Course
A1:courseid
E2:Course
A1:semesterid
E2: Semester
E3:Semester
2
ANSWER:
Templates (please remove after using)
E1: Customer
(1 E1: Customer “Place” M E6: Orders)
R2: Place
E1: Customer – A1: C_ID
3
b. (5 pts) Professors can teach the same course in several semesters, and only the most
recent such offering needs to be recorded. (Assume this condition applies in all
subsequent questions.)
ANSWER:
A1:courseid
A1:social security
number
E1:Professors
E2:Course
R1:teaches
A1:semesterid
4
c. (5 pts) Every professor must teach some course.
ANSWER:
A1:courseid
A1:social security
number
E1:Professors
R1:teaches
A1:semesterid
E3:Semester
5
Relational Model
Given the ERD below (one salesperson, many customers),
s
Salesperson
Customer
Show the Relational Model using SQL like statements that create the TABLEs
including the foreign key and primary key indications.
Assume that sid and cid are CHAR(10) type.
Use the second approach from the book (i.e. no separate Table for the relationship set if
many to one!)
ANSWER:
CREATE TABLE Salesperson(
sid
CHAR(10),
PRIMARY KEY (sid));
CREATE TABLE Customers(
cid
CHAR(10),
PRIMARY KEY (cid, sid),
FOREIGN KEY (sid) REFERENCES Salesperson(sid));
6
3. (20 points)
Normalization.
Please use the LECTURE Notations!
1.
(10 points) Given Relation R(A, B, C, D) and the set of FDs F ={
ABC -> D
D -> A
}.
Identify the candidate key(s) for R and state its strongest normal form. If
appropriate, decompose R to BCNF. You need to show all your work!
(you can draw the template over the functional dependencies above)
ANSWER:
X->A
A
B
C
D
(ABC)*->D
A
B
C
D
D* ->A
A
D
Candidate keys: ABC
R is not BCNF because D is not a key.
7
2.
(10 points)
Given Relation R(A, B, C, D) and the set of FDs F ={
A -> B,
A -> C,
BC -> D
}
Identify the candidate key(s) for R and state its strongest normal form. If
appropriate, decompose R to BCNF. You need to show all your work!
(you can draw the template over the functional dependencies above)
ANSWER:
X->?
A
B
C
D
A -> B
A
B
C
D
A -> C
A
B
C
D
B
C
D
BC -> D
Candidate keys: A
R is in 1NF because there is no multi value or composite value.
R is in 2NF because X contain A is a super key for R and no partial dependency.
R is in 3NF because X contain A is a super key for R.
Strongest normal form of R is 3NF
BC->D, BC is not a key, decompose R1(B,C,D), R2(A,B,C)
8
4. (15 points)
Normalization.
Please use the LECTURE NOTATIONS!
a. (5 pts) Given Relation R(A, B, C, D) and the set of FDs F={
AB
AB
C
D




C
D
A
B
}.
Identify the candidate key(s) for R.
You need to show all your work!
(you can draw the template over the functional dependencies above)
ANSWER:
X->?
AB->C
AB->D
C->A
D->B
BC
CD
AD
A
A
A
A
A
A
A
B
B
B
B
B
B
B
C
C
C
C
C
C
C
D
D
D
D
D
D
D
Candidates key: AB, BC, CD, AD
9
b. (5 pts) Given Relation R(A, B, C, D) and the set of FDs F={
AB
BD
D
B




C
A
A
C
}.
Is R in 3NF?
You need to show all your work!
(you can draw the template over the functional dependencies above)
ANSWER:
X->?
A
AB->C
A
BD->A
A
D->A
A
B->C
Candidates key: BD
B
B
B
C
C
C
B
C
D
D
D
R is not 3nF because A, C are not part of BD
10
c. (5 pts) Given Relation R(A, B, C, D) and the set of FDs F={
ABC
BCD
D




D
A
C
ACD
B
}.
Is R in BCNF?
You need to show all your work!
(you can draw the template over the functional dependencies above)
ANSWER:
X->?

BCD  A
ABC
D

C
ACD

D
B
A
B
C
D
A
B
C
D
A
B
C
D
C
D
C
D
A
R is not in BCNF because D->C, D is not a super key so it violates BCNF
11
5. (40 points)
Decomposition
Examine the Relation/Table TempStaffAllocation shown below:
TempStaffAllocation
staffNo
branchNo
branchAddress
name
position
hoursPerWeek
S4555
B002
City Center Plaza, Seattle, WA 98122
Ellen Layman
Assistant
16
S4555
B004
16 – 14th Avenue, Seattle, WA 98128
Ellen Layman
Assistant
9
S4612
B002
City Center Plaza, Seattle, WA 98122
Dave Sinclair
Assistant
14
S4612
B004
16 – 14th Avenue, Seattle, WA 98128
Dave Sinclair
Assistant
10
1. (10 points) Why is this table not in 2NF? Please use the LECTURE Notations!
ANSWER: This table is not in 2NF since the attribute branchAddress only depend
on stage branchNo and doesnot depend on staffNo. To be in 2nf, the table need to
have attribute A depend on all stages X. This table have partial dependencies, so it is
not in 2NF
12
2. (10 points) Describe and illustrate the process of normalizing the data shown in this
Relation/Table to third normal form (3NF). Please use the LECTURE Notations!
ANSWER:
staffNo
branchNo
hoursPerWeek
S4555
B002
16
S4555
B004
9
S4612
B002
14
S4612
B004
10
branchNo
branchAddress
B002
City Center Plaza, Seattle, WA 98122
B004
16 – 14th Avenue, Seattle, WA 98128
B002
City Center Plaza, Seattle, WA 98122
B004
16 – 14th Avenue, Seattle, WA 98128
staffNo
name
position
S4555
Ellen Layman
Assistant
S4555
Ellen Layman
Assistant
S4612
Dave Sinclair
Assistant
S4612
Dave Sinclair
Assistant
13
3. (10 points) Identify the primary and foreign keys in your 3NF Relations/Tables.
Please use the LECTURE Notations!
ANSWER:
Primary keys:
staffNo
branchNo
Foreign keys:
branchAddress
name
position
4. (10 points) Create the Entity Relationship Diagram (ERD) using the PROPER ERD
Language to represent the data shown in the Tables. Your ERD model should show all
Labeled and Numbered Entity Sets, Relationship Sets, and Labeled & Numbered
Attributes, and Cardinalities.
ANSWER:
branchNo
StaffNo
(1 E1: staff “work” M E2: branch)
Name
position
Staff
Work
branchAddress
Branch
TempStaffAllocation
Open
hourPerweek
14
Download