Day 40

advertisement
CS 3630
Database Design and
Implementation
1
Final Exam
•
•
•
•
7:00 – 8:52 PM, Thursday, May 16
Section 1: Ull 009
Section 2: Ull 206
100 Points
– 50 points on design
– 50 points on SQL
• Open Book/Note/Computer
• Do it yourself
2
Set Theory
3
Relational Algebra
Selection
:
Projection
:
Cartesian Product:
Theta Join
:
Natural Join
:
Out Join
:
 (predicate) (R)
Att1, Att3 (R)
R S
R pS
R S
R S
4
Design Methodology
A structured approach that uses procedures, techniques, tools, and
documentation aids to support and facilitate the process of design.
Three main phases
1.
Conceptual database design
E-R Model
2.
Logical database design
Mapping E-R Model to (relational) database schema (DBDL)
Normalization
3.
Physical database design
5
Mapping Entity
Multi-value and Composite Attribute
Student
studentNo
Name: Composite (first, last)
CoursesTaken: Multi-Value
...
Table Schema
Student (studentNo, firstName, lastName . . .)
AcademicProg(studentNo, CourseID)
(one student will have multiple records in the table)
6
Mapping Relationships
EntityOne (1) ----- Related ----- (0..*) EntityTwo
Owner (1) ----- Owns ----- (0..*) Property
One-to-Many
Parent table: EntityOne / Owner
Copy PK of parent table into child table as FK
EntityThree (0..*) ----- Related ----- (1..*) EntityFour
Staff (1..*) ----- AssignedTo ----- (0..*) Ward
Many-to-Many
Create a new table
One-to-One
7
Mapping Relationships
Entity3 (0..*) ----- Related ----- (1..*) Entity4
Att1, Att2
Entity3 (A1, A2, A3)
Entity4 (B1, B2, B3, B4)
NewTable (A1, B1, B2, Att1, Att2, NewAtt)
PK: NewAtt
AK: ?
FK: A1 References Entity3
B1, B2 References Entity4
8
How to Describe a Table Schema?
Database Design Language (DBDL)
Branch (Bno, Street, City, State, Zipcode, Phone)
PK: Bno
AK: Street, City, Zipcode
Phone
FK: None
Staff (Sno, firstName, lastName, Address, Bno )
PK: Sno
AK: None
FK: Bno references Branch
Client (Cno, firstName, lastName, Phone, MaxRent, PrefType)
PK: Cno
AK: None
FK: None
Viewing (Rno, Pno, ViewDate, Comment)
PK: Rno, Pno, Vie wDate
AK: None
FK: Rno references Client (Cno)
Pno references Property
No multi-value attributes, no composite attributes.
1NF
9
Design Methodology
A structured approach that uses procedures, techniques, tools, and
documentation aids to support and facilitate the process of
design.
Three main phases
1.
Conceptual database design
E-R (EER) Model
2.
Logical database design
Mapping E-R Model to (relational) database schema
(Derive table / database schema)
Normalization
3.
Physical database design
10
Normalization
•
•
•
•
•
•
Why?
Functional Dependency
1NF
2NF
3NF
BCNF
• DBDL for schema
• Instance to show records
11
Decompose table R into BCNF
R (A, B, C, D, E, F)
Functional Dependencies:
A, B ---> All
A ---> C
B ---> E, F
R1 (A, C)
Primary Key: A
Alternate Key: None
Foreign Key: None
A ---> C
R2 (B, E, F)
Primary Key: B
Alternate Key: None
Foreign Key: None
B ---> E, F
R3 (A, B, D)
Primary Key: A, B
Alternate Key: None
Foreign Key: A References R1
B References R2
A, B ---> D
12
Table Instance
A
1
1
2
2
R1
A C
1 10
2 20
B
x
y
B
x
y
x
y
R2
E
cs
cs
R
C
10
10
20
20
D
100
200
300
400
E
cs
cs
cs
cs
F
se
ee
se
ee
R3
F
se
ee
A
1
1
2
2
B
x
y
x
y
D
100
200
300
400
13
Database Queries
•
•
•
•
•
Tables needed
Join condition
Group By
Outer Join and Sub-Query
All clients without class today
14
Download