Carnegie Mellon University © Robert T. Monroe Management Information Systems Data Modeling II – Relationships Management Information Systems Robert Monroe October 25, 2011
Carnegie Mellon University © Robert T. Monroe Management Information Systems Goals For Today By the end of today's class you should be able to: –Identify basic relationships between entities –Apply the concept of degree of relationships (unary, binary, ternary) to your ER models –Apply the concept of cardinality constraints in relationships (one-to-one, one-to-many, many-to-many) to your ER models –Use associative entities in your ER models appropriately
Carnegie Mellon University © Robert T. Monroe Management Information Systems Entity-Relationship (ER) Data Modeling
Carnegie Mellon University © Robert T. Monroe Management Information Systems Quick Review: ER Modeling Core Elements Entity A person, place, object, event, concept in the user environment about which the organization wishes to maintain data. Attribute A property or characteristic of an entity that is of interest to the organization. Relationship A meaningful association between, or among, entities. Entity Attribute … PersonCar owns Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Quick Review: E-R Diagram Notation Entity symbols A special entity that is also a relationship Relationship symbols Attribute symbols Relationship cardinalities specify how many of each entity type is allowed Relationship degrees specify number of entity types involved Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Relationships A relationship defines a meaningful association between, or among, entities –Modeled as a line drawn between entities Relationships can have attributes –These describe features pertaining to the association between the entities in the relationship. Two entities can have more than one type of relationship between them (multiple relationships)
Carnegie Mellon University © Robert T. Monroe Management Information Systems Degree of Relationship Defines the number of entity types that participate in it Unary Relationship –One entity type related to itself Binary Relationship –Two entity types related to each other Ternary Relationship –Three entity types related to each other It is possible, but unusual, to have relationship types of larger than 3 entities
Carnegie Mellon University © Robert T. Monroe Management Information Systems Defines the number of entity instances that participate in it One-to-One –Each entity in the relationship will have exactly one related entity One-to-Many –An entity on one side of the relationship can have many related entities, but an entity on the other side will have a maximum of one related entity Many-to-Many –Entities on both sides of the relationship can have many related entities on the other side Cardinality of Relationships
Carnegie Mellon University © Robert T. Monroe Management Information Systems Cardinality Constraints The number of instances of one entity that can or must be associated with each instance of another entity –Mandatory one –Mandatory many –Optional one –Optional many
Carnegie Mellon University © Robert T. Monroe Management Information Systems Example: Unary Degree Relationship Employee Name Title Ahmed CEO Maha VP, Sales Roula Sales Associate Noor Sales Associate James CFO Yassar COO Roberto Facilities Mgr Fatima Operations Mgr ReportsTo ER Relationship: Employee ReportsTo Employee Organizational chart showing employee Reporting relationships in a company Note: This is NOT an ER Diagram!
Carnegie Mellon University © Robert T. Monroe Management Information Systems Example: Binary Relationships Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Example: Binary Relationship With An Attribute The Date_Completed attribute pertains specifically to the employee’s completion of a course It is an attribute of the relationship, not either entity in isolation Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Example: Ternary Relationship With Attributes Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Exercises: Describe Relationship Degree and Cardinality Website: Qatar MOI Traffic Violations Entities: Vehicle and Violation Relationship: a Vehicle is charged with a Violation Degree: Binary (2 entity types – Vehicle and Violation) Cardinality: One to Many (Vehicle to Violation)
Carnegie Mellon University © Robert T. Monroe Management Information Systems Exercises: Describe Relationship Degree and Cardinality Website: Blackboard Entities: Courses and Students Relationship: Degree: Cardinality:
Carnegie Mellon University © Robert T. Monroe Management Information Systems Exercises: Describe Relationship Degree and Cardinality Website: Qatar National Bank (QNB) Entities: Customer and Account Relationship: Degree: Cardinality:
Carnegie Mellon University © Robert T. Monroe Management Information Systems Exercises: Describe Relationship Degree and Cardinality Website: Facebook Entities: Friends and Messages Relationship: Degree: Cardinality:
Carnegie Mellon University © Robert T. Monroe Management Information Systems Exercises: Describe Relationship Degree and Cardinality Website: Flickr Entities: Picture, User, Portfolio Relationship(s): Degree: Cardinality:
Carnegie Mellon University © Robert T. Monroe Management Information Systems Associative Entities It’s an entity – it has attributes AND it’s a relationship – it links entities together When should a relationship with attributes instead be an associative entity? –All relationships for the associative entity should be many –The associative entity could have meaning independent of the other entities –The associative entity preferably has a unique identifier, and should also have other attributes –The associative entity may participate in other relationships other than the entities of the associated relationship –Ternary relationships should generally be converted to associative entities
Carnegie Mellon University © Robert T. Monroe Management Information Systems Example: Associative Entity Associative entity are represented as a rectangle with rounded corners Note that the many-to-many cardinality symbols face toward the associative entity and not toward the other entities Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems Flickr Exercise: Repeat with Associative Entity Website: Flickr Entities: Picture, User, Portfolio Relationship(s): Degree: Cardinality:
Carnegie Mellon University © Robert T. Monroe Management Information Systems In-Class Exercise (Part III) – Create E-R Diagram Produce an E-R diagram capturing –Entities –Attributes –Relationships Source: [HPM09]
Carnegie Mellon University © Robert T. Monroe Management Information Systems In-Class Exercise: Create E-R Diagram CoolClothes Inc. sells many different products in their retail stores. Basic ER Model: The retail stores are organized geographically. Each store is classified by the city, country, and region in which it is located. CoolClothes would like to be able to track the quantity of each product are in stock at each store. –Each product is uniquely identified by its SKU number, or Stock Keeping Unit –Each SKU can represent a product that is available in multiple sizes and multiple colors (but all colors and sizes have the same SKU) –CoolClothes wants to track the quantity of each item in each size and color, at each store location. More Advanced: Update the model to allow tracking the current asking price for each product, the original asking price, and whether it is currently on sale. Each retail store decides independently which items will be put on sale.
Carnegie Mellon University © Robert T. Monroe Management Information Systems Administrivia: Adjustment To Data Management Classes Sunday, October 30: Relational Data Model Tuesday, November 1: “Big Data”, Data Warehousing Sunday, November 13: Business Analytics Tools
Carnegie Mellon University © Robert T. Monroe Management Information Systems References [HPM09] Jeffrey Hoffer, Mary Prescott, Fred McFadden, Modern Database Management, 9 th Ed., Pearson - Prentice Hall, 2009, ISBN: