27
CS 3630 Database Design and Implementation

Design Methodology

Embed Size (px)

DESCRIPTION

Design Methodology. A structured approach that uses procedures, techniques, tools, and documentation aids to support and facilitate the process of design. Three main phases Conceptual database design Understanding client data E-R (EER) Model - PowerPoint PPT Presentation

Citation preview

Page 1: Design Methodology

CS 3630 Database Design and Implementation

Page 2: Design Methodology

2

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 Understanding client data E-R (EER) Model Agreement between clients and designers E-R Model could be used for any database system

2. Logical database design Mapping E-R Model to (relational) database schema Normalization

3. Physical database design

Page 3: Design Methodology

3

Mapping E-R Model to Relational Database Schema

1. Entity type Table schema

2. How to maintain relationships?

Page 4: Design Methodology

4

Mapping Strong Entities to Relation (Table) Schemas

• Replacing composite attributes with simple attributes

• Adding new tables to remove multi-value attributes

Page 5: Design Methodology

5

Replacing Composite Attributes with Simple Attributes

Name: Composite (FirstName, LastName)

Use two atriibutes:

FirstName

LastName

Address : Compsite (Street, City, State, Zipcode)

Use four attributes:

Street

City

State

Zipcode

Performance issue

Page 6: Design Methodology

6

Composite Attributes

staffNo Name Address . . .

SL21 John White 1 main street, Platteville, WI 53818

SG37 Ann Beech 15 University Dr, Madison, WI 53706

SA9 Mary Howe 908 Western avenue, Dubuque, IA 52001-1234

Search/Project on state or zip code

Page 7: Design Methodology

7

Simple Attributes

staffNo firstName lastName Street City State zip

SL21 John White 1 main street Platteville WI 53818

SG37 Ann Beech 15 University Dr Madison WI 53706

SA9 Mary Howe 908 Western avenue

Dubuque IA 52001-1234

Search/Project on state or zip code

Page 8: Design Methodology

E-R Model

Staff

StaffNo

Name:

Simple or Composite?

Address

Simple or Composite?

Salary

. . .

8

Page 9: Design Methodology

9

Removing Multi-Value Attributes

No multi-value attributes in relational databases

First Order Logic

No sets as set elements

Page 10: Design Methodology

10

Multi-Value Attributes

branchNo street city state zipCode telNo

B001 1 main street

Platteville WI 53818 608-348-1234

608-348-3345

B002 15 university drive

Madison WI 53706 608-255-3034

608-255-1023

877-323-5678

… … … … … …

Page 11: Design Methodology

11

Removing Multi-Value Attributes without Losing Data

Entity Type in E-R ModelBranch branchNo . . . telNo: multi-value

How to Store telNo? phoneOne phoneTwo phoneThree

(When we know the limit of phone numbers at a branch: at most three)

Staff staffNo homePhone workPhone cellPhone . . .

Page 12: Design Methodology

12

Each Branch Has at Most Three Phone Numbers

branchNo street . . . phone1 phone2 phone3

B001 1 main street

608-348-1234 608-348-3345

B002 15 university drive

608-255-3034 608-255-1023 877-323-5678

… … … … …

Page 13: Design Methodology

13

Home Phone, WorkPhone and Cell Phone

staffNo street . . . homePhone workPhone cellPhone

SL21 1 main street

608-348-1234 608-348-3345

SG37 15 university drive

608-255-1023 877-323-5678

SA79 … … 608-255-3034 608-255-3847

Page 14: Design Methodology

14

Multi-Value Attributes Without Limit

Entity Type in E-R ModelBranch branchNo . . . telNo: multi-value (NO LIMIT!)

More Examples

Student MajorWork Experience

Research publications . . .

Page 15: Design Methodology

15

Replacing Multi-Value Attributes

branchNo . . . telNo

B001 608-348-1234

608-348-3345

B002 608-255-3034

608-255-1023

877-323-5678

… … …

branchNo Street City State zipCode

B001

B002

branchNo telNo

B001 608-348-1234

B001 608-348-3345

B002 608-255-3034

B002 608-255-1023

B002 877-323-5678

… …One table two tablesMulti-Value attribute multiple recordsPrimary Key Foreign Key

Page 16: Design Methodology

16

Replacing Multi-Value Attributes

Entity Type in E-R ModelBranch branchNo . . . telNo: multi-value (NO LIMIT!)

How to Store telNo?Remove it from Branch and create a new table!

BranchPhone branchNo telPhone

Which attributes should be in the new table?The PK attribute(s) and the multi-value attribute.

Page 17: Design Methodology

17

Replacing Multi-Value Attributes

Entity Type in E-R ModelBranch branchNo . . . telNo: multi-value (NO LIMIT!)

BranchPhone branchNo telPhone

What is the PK?Assumption: two branches don’t share the same phone #

Does it have a FK?

Page 18: Design Methodology

18

Mapping Entity Type to Table Schema

Entity Type in E-R ModelBranch branchNo address: composite (street, city, state, zipCode) telNo: multi-value (with or without limit!)

Table Schema (DBDL)

Branch (branchNo, street, city, state, zipCode) PK: branchNo AK: street, city, state, zipCode FK: NONE

BranchPhone (branchNo, telPhone) PK: telPhone AK: NONE FK: branchNo references Branch

Page 19: Design Methodology

19

Entity Type in E-R ModelStaff staffNo . . . DOB workExperince: multi-value Composite (start, end, org, position)

Store workExperince with staffNo in a new Table!WorkExperience staffNo start end org position

PK?Could create a new PK attribute (workExpID)

FK?

Mapping Entity Type to Table Schema

Page 20: Design Methodology

20

Storing Work ExperienceEntity Type in E-R Model

Staff staffNo . . . DOB workExperince: multi-value Composite (start, end, org, position)

Table Schema (DBDL)Staff (staffNo, . . ., DOB) PK: staffNo AK: NONE FK: NONE

WorkExperience(workExpID, staffNo, start, end, org, position) PK: workExpID AK: ? FK: staffNo references Staff

Page 21: Design Methodology

21

How to Represent Relationship?

Primary Key and Foreign Key!

1:11:* (1..m)*:* (m..n)Complex relationshipRecursive relationshipSuperclass / Subclass Relationship

Page 22: Design Methodology

22

One-to-Many (1:*)Owner (1) Owns (0..*) PropertyForRent

Parent entity: one side

Owner

Child entity: many side

PropertyForRent

Do we need a table for the relationship?

NO!

Copy PK of parent entity to child entity as FK

Copy Ono to PropertyForRent

Does it work to copy Pno to Owner?

Page 23: Design Methodology

23

Mapping Entities with Relationship to Table Schemas

E-R Model

Owner (Ono, firstName, lastName, Phone)

Property(Pno, Street, City, State, Zipcode, Rent)

Owner (1) Owns (0..*) Property

Table Schemas (DBDL)

Owner (Ono, firstName, lastName, Phone)

PK: Ono

AK:

FK: None

Property(Pno, Street, City, State, Zipcode, Rent, Ono)

PK: Pno

AK: Street, City, Zipcode

FK: Ono references Owner

Page 24: Design Methodology

24

ExampleE1 E2

A1 B1

A2 composite (A21, A22) B2: Multi-value

B3

PK: A1 PK: B1

E1 (1..*) RelatedTo (1) E2

Table Schemas (DBDL)

E1 (A1, A21, A22, B1) E2 (B1, B3)

PK: A1 PK: B1

AK: None AK: None

FK: B1 references E2 FK: None

E3 (B1, B2, NewID)

PK: NewID

AK: None

FK: B1 references E2

Page 25: Design Methodology

25

One-to-One (1:1)

Are the two entity types identical with different names?

Client -------- Customer

Staff ---------- Employee

Can the two entity types be combined into one entity type?

Client (1) Provides (1) RegstrationInfo

Client (1) Has (1) Interview

Page 26: Design Methodology

26

One-to-One (1:1)

The two entity types are not identical, and cannot be combined into one entity.

Do we need a new table for the relationship?

NO!

Copy one PK as FK.

Which Direction: Three Cases• Total on both sides• Partial both sides• Total on one side and Partial on the other side

Page 27: Design Methodology

Assignment 4

Individual Assignment

Due Friday, Feb 20

27