Top Banner
More Data Modeling CS 146
16

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

Jan 08, 2018

Download

Documents

Cory Jones

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: More Data Modeling CS 146. Relationship Lower Bounds  Lower bound: minimum number of related instances in a relationship  Value is typically 0 or 1.

More Data ModelingCS 146

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

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”

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

More Lower Bound Examples

StoreStore_IDStore_Address

VideoVideo_IDVideo_TitleVideo_Format

CustomerCustomer_IDCustomer_NameCustomer_Address

Rents

Rents

SpouseSpouse_IDSpouse_Name

Has

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

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

? ?

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

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

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

Composite Relationships:Another Example

HoursEmployee

EmployeeIDEmployeeName

WorksOn ProjectProjectID

ProjectName

Attribute ofthe relationship

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

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!

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

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

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

Unary Relationships Entity has a relationship with itself

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

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

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

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

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

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!

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

Homonyms Homonym: different attributes

have the same nameAvoid!Attributes should take their name

from their entityUniversityStudent

PK StudentID

Name

UniversityInstructor

PK InstructorID

Name

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

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?

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

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…

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

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