1 cs 3630 database design and implementation. 2 final exam 7:00 – 8:52 pm, thursday, may 16...

14
1 CS 3630 Database Design and Implementation

Upload: marilyn-mills

Post on 22-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

1

CS 3630 Database Design and

Implementation

Page 2: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

2

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

Page 3: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

Set Theory

3

Page 4: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

Relational Algebra

Selection : (predicate) (R)

Projection : Att1, Att3 (R)

Cartesian Product: R S

Theta Join : R p S

Natural Join : R S

Out Join : R S

4

Page 5: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

5

Design MethodologyA 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

Page 6: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

6

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)

Page 7: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

7

Mapping Relationships

EntityOne (1) ----- Related ----- (0..*) EntityTwoOwner (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..*) EntityFourStaff (1..*) ----- AssignedTo ----- (0..*) Ward Many-to-Many Create a new table

One-to-One

Page 8: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

8

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

Page 9: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

9

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: NoneStaff (Sno, firstName, lastName, Address, Bno ) PK: Sno AK: None FK: Bno references BranchClient (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

Page 10: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

10

Design MethodologyA 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

Page 11: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

11

Normalization

• Why?• Functional Dependency• 1NF• 2NF• 3NF• BCNF

• DBDL for schema• Instance to show records

Page 12: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

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

R (A, B, C, D, E, F)

Functional Dependencies: A, B ---> All A ---> C B ---> E, F

Decompose table R into BCNF

Page 13: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

Table Instance R

A B C D E F

1 x 10 100 cs se

1 y 10 200 cs ee

2 x 20 300 cs se

2 y 20 400 cs ee

R1

A C

1 10

2 20

R2

B E F

x cs se

y cs ee

R3

A B D

1 x 100

1 y 200

2 x 300

2 y 40013

Page 14: 1 CS 3630 Database Design and Implementation. 2 Final Exam 7:00 – 8:52 PM, Thursday, May 16 Section 1: Ull 009 Section 2: Ull 206 100 Points –50 points

14

Database Queries

• Tables needed

• Join condition

• Group By

• Outer Join and Sub-Query

• All clients without class today