250 likes | 362 Views
Modeling Relationships. Data Modeling and Relational Database Design. Objectives. Analyze and model the relationships between entities Draw an initial entity relationship diagram Read the relationships on an ER diagram Clearly define relationship names. Relationship Definitions.
E N D
Modeling Relationships Data Modeling and Relational Database Design
Objectives • Analyze and model the relationships between entities • Draw an initial entity relationship diagram • Read the relationships on an ER diagram • Clearly define relationship names
Relationship Definitions • The way one entity relates to another • The business rules that link together business information needs • What one thing has to do with another • A named association between entities
Bi-directional Relationships SMT COURSE SMT COURSE DMDD COURSE INSTRUCTOR COURSE
Diagramming Conventions • A line between two entities • Lower case relationship name • Optionality (Minimum cardinality) • Degree (Maximum cardinality) Mandatory - must be Optional - may be One or more One and only one
COPY TITLE Diagramming Conventions many (crow’s foot) optional one mandatory
Relationship Syntax one or more or one and only one must be or may be relationship name Each entity 1 entity 2 Object entity Subject entity Name Optionality Degree
Validation - in class practice assigned to EMPLOYEE DEPARTMENT
Validation - in class solution assigned to EMPLOYEE DEPARTMENT Each EMPLOYEE must be assigned to one and only one DEPARTMENT
Validation - in class practice EMPLOYEE DEPARTMENT responsible for
Validation - in class solution EMPLOYEE DEPARTMENT responsible for Each DEPARTMENT may be responsible for one or more EMPLOYEES
Validation - in class solution assigned to EMPLOYEE DEPARTMENT DEPARTMENT EMPLOYEE responsible for Each EMPLOYEE must be assigned to one and only one DEPARTMENT Each DEPARTMENT may be responsible for one or more EMPLOYEES
Validation - in class practice enrolled in COURSE STUDENT taken by
Validation - in class solution enrolled in COURSE STUDENT taken by Each STUDENT may be enrolled in one or more COURSES Each COURSE may be taken by one or more STUDENTS
Relationship Types Many-to-One Many-to-Many One-to-One
Many-to-One Relationships visited by SALES REPRESENTATIVE CUSTOMER assigned to
Many-to-Many Relationships attended by HEALTH CARE WORKER PATIENT assigned to
One-to-One Relationships is ridden by BICYCLE CYCLIST the rider of Represents a snapshot in time
Analyzing & Modeling Relationships • Determine the existence of a relationship • Name each direction of the relationship • Determine the degree of each direction of the relationship • Determine the optionality of each direction of the relationship • Read the relationship aloud to validate it
COPY Determining a Relationship’s Existence Existence Name MEMBERSHIP RENTAL COPY Degree MEMBERSHIP Optionality Validate COPY RENTAL MEMBERSHIP RENTAL
TITLE COPY Naming the Relationship Existence Each title is available as a copy and each copy is of a title Name Degree Optionality Validate of available as
TITLE COPY Determining the Degree Existence Each title is available as a copy, there could be lots of copies but there is only ever one title on a copy Name Degree Optionality Validate one many
TITLE COPY Determining the Optionality Every copy must have a title on it but we need information about titles even if there is no copy Existence Name Degree Optionality Validate optional mandatory
TITLE COPY Validating the Relationship Each copy must be of one and only one title, and each title may be available as one or more copies Existence Name Degree Optionality Validate of available as
Summary • Establish the existence of a relationship • Name the relationship • Determine its degree • Determine its optionality • Read the relationship to validate it