More Data Modeling CS 146. Relationship Lower Bounds Lower bound: minimum number of related instances in a relationship Value is typically 0 or 1.

Post on 08-Jan-2018

219 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

More Lower Bound Examples Store Store_ID Store_Address Video Video_ID Video_Title Video_Format Customer Customer_ID Customer_Name Customer_Address Rents Spouse Spouse_ID Spouse_Name Has

Transcript

More Data ModelingCS 146

Relationship Lower Bounds Lower bound: minimum number of related

instances in a relationship Value is typically 0 or 1

StoreStore_IDStore_Address

VideoVideo_IDVideo_TitleVideo_Format

Rents

“A store rents 0 to many videos”

“A video can be rented by 1 and only 1 store”

More Lower Bound Examples

StoreStore_IDStore_Address

VideoVideo_IDVideo_TitleVideo_Format

CustomerCustomer_IDCustomer_NameCustomer_Address

Rents

Rents

SpouseSpouse_IDSpouse_Name

Has

How Do You Select Upper and Lower Bounds? Business rules of the organization Database design decisions

Example: Auto service center

Guidelines: Make the system as flexible as possible Avoid M:M relationships when possible

Increase system complexity

CarCar_IDCar_MakeCar_ModelCar_Year

CustomerCustomer_IDCustomer_NameCustomer_Address

owns

? ?

Composite Relationship Occurs for a relationship that has attributes Always has M:M cardinality

CourseGrade

StudentStudentID

StudentFirstNameStudentLastNameStudentAddress

StudentDOBStudentClass

EnrollsIn

CourseSectionCourseID

CourseDayCourseTime

CourseLocation

Attribute ofthe relationship

Composite Relationships:Another Example

HoursEmployee

EmployeeIDEmployeeName

WorksOn ProjectProjectID

ProjectName

Attribute ofthe relationship

CourseCourseID

CourseNameCourseDayCourseTime

CourseLocation

EnrollmentEnrollmentIDCourseGrade

StudentStudentID

StudentFirstNameStudentLastNameStudentAddress

StudentDOBStudentClass

Decomposing a Composite Relationship

Can always be decomposed into 2 1:M relationships!

CourseGrade

StudentStudentID

StudentFirstNameStudentLastNameStudentAddress

StudentDOBStudentClass

EnrollsIn

CourseCourseID

CourseNameCourseDayCourseTime

CourseLocation

Has Has

Note the direction of the 1:Ms!

Degree of a Relationship Specifies the number of entities that

participate in a relationship Up until now, all relationships have been

binary (2 entities)

VideoVideo_IDVideo_TitleVideo_Format

CustomerCustomer_IDCustomer_NameCustomer_Address

rents

Unary Relationships Entity has a relationship with itself

Ternary Relationships Relationship exists among 3 entities

UniversityStudent

PK StudentID

StudentFirstName StudentMI StudentLastName StudentDOB

UniversityCourse

PK CourseID

CourseName CourseDescription

UniversityTutor

PK TutorID

TutorFirstName TutorMI TutorLastNameSessionDate

SessionTimeSessionOutcome

Generalization/Specialization Relationships Do not show cardinalities

Supertype

Subtypes

UniversityPerson

PK PersonID

PersonFirstName PersonLastName

StudentPerson

PK StudentID

StudentMajor StudentCreditHours

FacultyPerson

PK FacultyID

FacDepartment FacRank FacSalary

StaffPerson

PK StaffID

StaffTitle StaffLevel StaffHourlyRate

How common are these? Unary

Rare Ternary, Generalization/Specialization

More common than you would think

Be aware that they can exist and how you represent them!

Homonyms Homonym: different attributes

have the same nameAvoid!Attributes should take their name

from their entityUniversityStudent

PK StudentID

Name

UniversityInstructor

PK InstructorID

Name

Synonyms Synonym: same attribute has

different names in different tables FK field should have same name as

PK field, unless another name makes it A LOT more descriptive

How should you change these entities?

Strategies for Developing ER Models How do you decide if an item is an entity or

an attribute? An item is an entity if…

An item is an attribute if…

Strategies for Associating an Attribute With the Correct Entity To which entity does an attribute belong?

Example: Is AdvisorName an attribute of a UniversityStudent instance?

Answer: Only if each advisor only advises only one student. Otherwise, you are repeating the name multiple times.

The ONLY thing that you can repeat in tables is a foreign key value!

Strategy: If a non-attribute appears in multiple entities, it

is not associated with the correct entity

top related