160 likes | 242 Views
More Data Modeling. CS 146. Relationship Lower Bounds. Lower bound: minimum number of related instances in a relationship Value is typically 0 or 1. Store Store_ID Store_Address. “A store rents 0 to many videos”. Rents. Video Video_ID Video_Title Video_Format.
E N D
More Data Modeling CS 146
Relationship Lower Bounds • Lower bound: minimum number of related instances in a relationship • Value is typically 0 or 1 Store Store_ID Store_Address “A store rents 0 to many videos” Rents Video Video_ID Video_Title Video_Format “A video can be rented by 1 and only 1 store”
More Lower Bound Examples Store Store_ID Store_Address Spouse Spouse_ID Spouse_Name Rents Has Video Video_ID Video_Title Video_Format Customer Customer_ID Customer_Name Customer_Address Rents
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 Car Car_ID Car_Make Car_Model Car_Year Customer Customer_ID Customer_Name Customer_Address owns ? ?
Composite Relationship • Occurs for a relationship that has attributes • Always has M:M cardinality Student StudentID StudentFirstName StudentLastName StudentAddress StudentDOB StudentClass CourseSection CourseID CourseDay CourseTime CourseLocation EnrollsIn CourseGrade Attribute of the relationship
Composite Relationships:Another Example Employee EmployeeID EmployeeName Project ProjectID ProjectName WorksOn Hours Attribute of the relationship
Decomposing a Composite Relationship • Can always be decomposed into 2 1:M relationships! Student StudentID StudentFirstName StudentLastName StudentAddress StudentDOB StudentClass Course CourseID CourseName CourseDay CourseTime CourseLocation EnrollsIn CourseGrade Course CourseID CourseName CourseDay CourseTime CourseLocation Student StudentID StudentFirstName StudentLastName StudentAddress StudentDOB StudentClass Enrollment EnrollmentID CourseGrade 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) Video Video_ID Video_Title Video_Format Customer Customer_ID Customer_Name Customer_Address rents
Unary Relationships • Entity has a relationship with itself
Ternary Relationships • Relationship exists among 3 entities
Generalization/Specialization Relationships • Do not show cardinalities Supertype Subtypes
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 name • Avoid! • Attributes should take their name from their entity
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