1 / 116

Designing an ER Diagram for the AAC Basketball League: From Modeling to Relational Schema

Explore the process of designing an Entity-Relationship (ER) diagram for the AAC basketball league, capturing team, player, coach, game, statistic, arena, and personnel information. Learn the essentials of the ER model and the conversion to relational schema in this detailed guide.

mdiaz
Download Presentation

Designing an ER Diagram for the AAC Basketball League: From Modeling to Relational Schema

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7: Entity-Relationship Model

  2. When All We Want Is an ER Diagram • Design Process • Modeling • Constraints • E-R Diagram • Design Issues • Weak Entity Sets • Extended E-R Features • Design of the Bank Database • Reduction to Relation Schemas • Database Design • UML

  3. Input: Plain Text

  4. The AAC league has multiple teams (11) each with a unique team name and a nickname (e.g., Temple is also known as the Owls). For each game played, there is a home team, an away team, home points, away points, and a date. All teams play multiple home and away games per season. Each game must have an away team and a home team. The teams all have players identified by name, team name, and number. The team name and number will be unique for each player, while their name may not be unique. There are twotypesof players forwards and centers in a team (Although, in general, there are more types of players in a basketball team, we ignore them in this exercise.) Each forward has a type {small or power}. Each center has a status {starter, bench}. Statistics are compiled for each game for each player. The Forward statistics will include steals, shooting percentage, and assists. The Center statistics include blocks, rebounds, and personal fouls. In addition, each team is represented by a single coach. A coach can coach only one team. Keep track of each coach's name and salary. A game takes place in an Arena, which has a location and a name. These attributes uniquely identify an Arena. Multiple games maybe scheduled in the same time in an Arena. Each scheduled game in an Arena is organized by NCAA personnel. An NCAA personnel is identified by a unique name. We also know the rank of an NCAA personnel.

  5. Output: An ER-Diagram

  6. Then: To Relational Schema Algorithm to convert an ER-Diagram to Relational Schema

  7. Entity-Relationship Model • Goals: • Capture semantics of information objects • Capture complex relationships between objects. • Developed by Peter Chen in 1976.

  8. The Entity-Relationship model • The E-R model is a detailed, logical representation of the data for an organization or business area • It should be understandable to both the user and to the IT technologist • The model must be as ‘open’ as possible and not tied to any technology or to any particular business methodology • It must be flexible enough so that it can be used and understood in practically any environment where information is modelled

  9. The ER model • It is expressed in terms of • Entities in the business environment • Relationships (or associations) among those entities and • Attributes (properties) of both the entities and their relationships • The E-R model is usually expressed as an E-R diagram

  10. Modeling • A database can be modeled as: • a collection of entities, • relationship among entities. • An entityis an object that exists and is distinguishable from other objects. • Example: specific person, company, event, plant • Entities have attributes • Example: people have names and addresses • An entity set is a set of entities of the same type that share the same properties. • Example: set of all persons, companies, trees, holidays

  11. Entity Sets instructor and student instructor_ID instructor_name student-ID student_name

  12. Relationship Sets • A relationship is an association among several entities Example: 44553 (Peltier)advisor 22222 (Einstein)student entity relationship set instructor entity • A relationship set is a mathematical relation among n 2 entities, each taken from entity sets {(e1, e2, … en) | e1  E1, e2  E2, …, en  En}where (e1, e2, …, en) is a relationship • Example: (44553,22222)  advisor

  13. Relationship Set advisor

  14. Relationship Sets (Cont.) • An attribute can also be property of a relationship set. • For instance, the advisor relationship set between entity sets instructor and student may have the attribute date which tracks when the student started being associated with the advisor

  15. Degree of a Relationship Set • binary relationship • involve two entity sets (or degree two). • most relationship sets in a database system are binary. • Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.) • Example: students work on research projects under the guidance of an instructor. • relationship proj_guide is a ternary relationship between instructor, student, and project

  16. Attributes • An entity is represented by a set of attributes, that is descriptive of the properties possessed by all members of an entity set. • Example: instructor = (ID, name, street, city, salary ) course= (course_id, title, credits) • Domain – the set of permitted values for each attribute • Attribute types: • Simple and composite attributes. • Single-valued and multivalued attributes • Example: multivalued attribute: phone_numbers • Derived attributes • Can be computed from other attributes • Example: age, given date_of_birth

  17. Composite Attributes

  18. Mapping Cardinality Constraints • Express the number of entities to which another entity can be associated via a relationship set. • Most useful in describing binary relationship sets. • For a binary relationship set the mapping cardinality must be one of the following types: • One to one (1-to-1, 1:1) • One to many (1-to-m, 1:m) • Many to one (m-to-1, m:1) • Many to many (m-to-n, m-to-m, n-to-n, m:n, m:m)

  19. Mapping Cardinalities One to many One to one Note: Some elements in A and B may not be mapped to any elements in the other set

  20. Examples Of 1:1 Relationships? • One dog belongs to one person (or one family). • One person has one passport. • The Easter Bunny is associated with one holiday.

  21. Examples Of 1:m Relationships? • A car and its parts. • Each part belongs to one car and one car has multiple parts. • A theater and shows. • One theatre usually has multiple shows and each show belongs to one theatre. • An relational schema and its tables. • An schema has one or more tables and each of the tables belongs to one schema. • Deans in a University. • One university has multiple deans and a dean belongs to one university.

  22. Mapping Cardinalities Many to one Many to many Note: Some elements in A and B may not be mapped to any elements in the other set

  23. Examples Of m:m Relationships? • Students and Courses. • Each student takes multiple courses, and each course is attended by multiple students. • A movie theater and movie. • A movie theatre has multiple movies, and a movies is played by multiple theatres. • Doctors and Patients. • One doctor, sees many patients; one patient sees many doctors. • Hotels and Guests. • One room can be booked by many guests, and a guest can book many rooms in the hotel. • Beers and Distributors.

  24. Keys • A super key of an entity set is a set of one or more attributes whose values uniquely determine each entity. • A candidate key of an entity set is a minimal super key • ID is candidate key of instructor • course_id is candidate key of course • Although several candidate keys may exist, one of the candidate keys is selected to be the primary key.

  25. Keys for Relationship Sets • The combination of primary keys of the participating entity sets forms a super key of a relationship set. • (s_id, i_id) is the super key of advisor • NOTE: this means a pair of entity sets can have at most one relationship in a particular relationship set. • Example: if we wish to track multiple meeting dates between a student and her advisor, we cannot assume a relationship for each meeting. We can use a multivalued attribute though • Must consider the mapping cardinality of the relationship set when deciding what are the candidate keys • Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key

  26. Redundant Attributes • Suppose we have entity sets • instructor, with attributes including dept_name • department and a relationship • inst_dept relating instructor and department • Attribute dept_name in entity instructor is redundant since there is an explicit relationship inst_dept which relates instructors to departments • The attribute replicates information present in the relationship, and should be removed from instructor • BUT: when converting back to tables, in some cases the attribute gets reintroduced, as we will see.

  27. E-R Diagrams • Rectangles represent entity sets. • Diamonds represent relationship sets. • Attributes listed inside entity rectangle • Underline indicates primary key attributes

  28. Entity With Composite, Multivalued, and Derived Attributes Composite Multivalued Derived

  29. Relationship Sets with Attributes

  30. Roles • Entity sets of a relationship need not be distinct • Each occurrence of an entity set plays a “role” in the relationship • The labels “course_id” and “prereq_id” are called roles. • Can you think of another example?

  31. Cardinality Constraints • We express cardinality constraints by drawing • A directed line (), signifying “one,” or • An undirected line (—), signifying “many,” between the relationship set and the entity set. • One-to-one relationship: • A student is associated with at most one instructor via the relationship advisor • A student is associated with at most one department via stud_dept

  32. One-to-One Relationship • one-to-one relationship between an instructor and a student • an instructor is associated with at most one student via advisor • and a student is associated with at most one instructor via advisor

  33. One-to-Many Relationship • one-to-many relationship between an instructor and a student • an instructor is associated with several (including 0) students via advisor • a student is associated with at most one instructor via advisor

  34. Many-to-One Relationships • In a many-to-one relationship between an instructor and a student, • an instructor is associated with at most one student via advisor, • and a student is associated with several (including 0) instructors via advisor

  35. Many-to-Many Relationship • An instructor is associated with several (possibly 0) students via advisor • A student is associated with several (possibly 0) instructors via advisor

  36. Participation of an Entity Set in a Relationship Set • Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set • E.g., participation of section in sec_course is total • every section must have an associated course • Partial participation: some entities may not participate in any relationship in the relationship set • Example: participation of instructor in advisor is partial

  37. Alternative Notation for Cardinality Limits • Cardinality limits can also express participation constraints

  38. E-R Diagram with a Ternary Relationship

  39. Cardinality Constraints on Ternary Relationship • We allow at most one arrow out of a ternary (or greater degree) relationship to indicate a cardinality constraint • E.g., an arrow from proj_guide to instructor indicates each student has at most one guide for a project

  40. Cardinality Constraints on Ternary Relationship • If there is more than one arrow, there are two ways of defining the meaning. • E.g., a ternary relationship R between A, B and C with arrows to B and C could mean 1. each A entity is associated with a unique entity from B and C or 2. each pair of entities from (A, B) is associated with a unique C entity, and each pair (A, C) is associated with a unique B • Each alternative has been used in different formalisms • To avoid confusion we outlaw more than one arrow

  41. Example 1: Problem 1 Practice Ex 1 from the book ER Diagram for a car insurance company whose customers own one or more cars each. Each car has associated with it zero to any number of recorded accidents. Each insurance policy covers one or more cars, and has one or more premium payments associated with it. Each payment is for a particular period of time, and has an associated due date, and the when the payment was received.

  42. Step 1: Look for Entities • Most of the time they are among the nouns. ER Diagram for a car insurance company whose customers own one or more cars each. Each car has associated with it zero to any number of recorded accidents. Each insurance policy covers one or more cars, and has one or more premium payments associated with it. Each payment is for a particular period of time, and has an associated due date, and the date when the payment was received.

  43. Step 2: Look for Relationships • Most of the time they are among the verbs. ER Diagram for a car insurance company whose customersown one or more cars each. Each car has associated with it zero to any number of recorded accidents. Each insurance policy covers one or more cars, and has one or more premium payments associated with it. Each payment is for a particular period of time, and has an associated due date, and the date when the payment was received.

  44. ER Diagram: first draft

  45. Step 3: Look for Attributes • Most of the time they are clearly defined, not in this example though... ER Diagram for a car insurance company whose customersown one or more cars each. Each car has associated with it zero to any number of recorded accidents. Each insurance policy covers one or more cars, and has one or more premium payments associated with it. Each payment is for a particular period of time, and has an associated due date, and the date when the payment was received.

  46. ER Diagram: Attributes

  47. Step 4: Refine the Relationships • Need to read carefully. ER Diagram for a car insurance company whose customersownone or more cars each. Each car has associated with it zero to any number of recorded accidents. Each insurance policy coversone or more cars, and hasone or more premium payments associated with it. Each payment is for a particular period of time, and has an associated due date, and the date when the payment was received.

  48. ER Diagram: Refining the Relationships

  49. Weak Entity Sets • An entity set that does not have a primary key is referred to as a weak entity set. • The existence of a weak entity set depends on the existence of a identifying entity set • It must relate to the identifying entity set via a total, one-to-many relationship set from the identifying to the weak entity set • Identifying relationship depicted using a double diamond • The discriminator(or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set. • The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.

More Related