Upload
timothy-hanson
View
40
Download
1
Tags:
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
CS 3630 Database Design and Implementation
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
3
Mapping E-R Model to Relational Database Schema
1. Entity type Table schema
2. How to maintain relationships?
4
Mapping Strong Entities to Relation (Table) Schemas
• Replacing composite attributes with simple attributes
• Adding new tables to remove multi-value attributes
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
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
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
E-R Model
Staff
StaffNo
Name:
Simple or Composite?
Address
Simple or Composite?
Salary
. . .
8
9
Removing Multi-Value Attributes
No multi-value attributes in relational databases
First Order Logic
No sets as set elements
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
… … … … … …
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 . . .
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
… … … … …
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
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 . . .
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
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.
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?
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
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
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
21
How to Represent Relationship?
Primary Key and Foreign Key!
1:11:* (1..m)*:* (m..n)Complex relationshipRecursive relationshipSuperclass / Subclass Relationship
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?
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
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
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
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
Assignment 4
Individual Assignment
Due Friday, Feb 20
27