1 / 61

Entity-Relationship Model: Design and Principles

Learn about the Entity-Relationship Model in database systems, including information storage, element relationships, constraints, and design principles. This article covers entity sets, attributes, relationships, diagrams, instances, multiplicity, multiway relationships, roles, attributes on relationships, converting multiway relationships, subclasses, and design principles such as faithfulness, avoiding redundancy, simplicity, and choosing the right relationships and elements.

gagne
Download Presentation

Entity-Relationship Model: Design and Principles

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. 4.1 The Entity-Relationship Model • Design phrase 1) What information will be stored 2) How information elements will be related to one another 3) What constraints may be assumed (See Fig. 4.1) • High-level models: 1) E/R (Entity/Relationship) diagram 2) UML (Unified Modeling Language) 3) ODL (Object Description Language) • Starting with a high-level model and then converting the design to the relational model Database Systems

  2. 4.1 The Entity-Relationship Model Database Systems

  3. 4.1 The Entity-Relationship Model • Three principal element types: • 1) Entity sets • 2) Attributes • 3) Relationships • 4.1.1 Entity Sets • Entity set ↔ class • However, the E/R model is a static concept, involving the structure of data and not the operations on data. • 4.1.2 Attributes • we assume that attributes are of primitive types, such as strings, integers, or reals. Database Systems

  4. 4.1 The Entity-Relationship Model • 4.1.3 Relationships • Relationships are connections among two or more entity sets. • 4.1.4 Entity-Relationship Diagrams • Entity set ↔ rectangle • Attribute ↔ oval • Relationship ↔ diamond • (See Fig. 4.2) Database Systems

  5. 4.1 The Entity-Relationship Model Database Systems

  6. 4.1 The Entity-Relationship Model • 4.1.5 Instances of an E/R Diagram • A relationship R that connects n entity sets E1, E2, …, En may be imagined to have an “instance” that consists of a finite set of tuples (e1, e2, …, en), where each ei is chosen from the entities that are in the current instance of entity set Ei. • 4.1.6 Multiplicity of Binary E/R Relationships • Many-one • One-one • Many-many • The arrows means “at most one” • (See Fig. 4.3) Database Systems

  7. 4.1 The Entity-Relationship Model Database Systems

  8. 4.1 The Entity-Relationship Model 4.1.7 Multiway Relationships • Example (See Fig. 4.4) 4.1.8 Roles in Relationships • It is possible that one entity set appears two or more times in a single relationship. • Each line to the entity set represents a different role that the entity set plays in the relationships. • Example (See Fig. 4.5 and Fig. 4.6) Database Systems

  9. 4.1 The Entity-Relationship Model Database Systems

  10. 4.1 The Entity-Relationship Model Database Systems

  11. 4.1 The Entity-Relationship Model Database Systems

  12. 4.1 The Entity-Relationship Model 4.1.9 Attributes on Relationships • Example (See Fig. 4.7) • We can instead invent a new entity set, whose entities have the attributes ascribed to the relationship. (See Fig. 4.8) 4.1.10 Converting Multiway Relationships to Binary • Any relationship connecting more than two entity sets can be converted to a collection of binary, many-one relationships. • A connecting entity set (See Fig. 4.9) Database Systems

  13. 4.1 The Entity-Relationship Model Database Systems

  14. 4.1 The Entity-Relationship Model Database Systems

  15. 4.1 The Entity-Relationship Model Database Systems

  16. 4.1 The Entity-Relationship Model 4.1.11 Subclasses in the E/R Model • “isa” relationships “an A is a B” expresses an “isa” relationship from entity set A to entity set B. (See Fig. 4.10) • Example e.g., Roger Rabbit The three components are connected into one entity by the isa relationships. Database Systems

  17. 4.1 The Entity-Relationship Model Database Systems

  18. 4.2 Design Principles • 4.2.1 Faithfulness • First and foremost, the design should be faithful to the specifications of the application. • 4.2.2 Avoiding Redundancy • We should be careful to say everything once only. • e.g., having an attribute studioName of entity set Movies • Reasons: • 1) Extra space is required to represent the data. • 2) An update-anomaly potential Database Systems

  19. 4.2 Design Principles • 4.2.3 Simplicity Counts • Avoiding introducing more elements into your design than is absolutely necessary. • (See Fig. 4.11) • 4.2.4 Choosing the Right Relationships • Adding to our design every possible relationship is not often a good idea. • 1) Redundancy • 2) Update anomaly • 3) Delete anomaly • Example (See Fig. 4.7 and Fig. 4.12) Database Systems

  20. 4.2 Design Principles Database Systems

  21. 4.2 Design Principles Database Systems

  22. 4.2 Design Principles Database Systems

  23. 4.2 Design Principles • 4.2.5 Picking the Right Kind of Element • Using attributes or using entity sets? • Example • Make the name and address of the studio be attributes of • movies and eliminate the Studio entity set. • Problems: • 1) Redundancy: the address of the studio • 2) Update anomaly • 3) Delete anomaly • If we did not record addresses of studios, then there is no • harm in making the studio name an attribute of movies. Database Systems

  24. 4.2 Design Principles • The conditions under which we prefer to use an attribute instead of an entity set: • 1) All relationships in which E is involved must have • arrows entering E. • 2) The only key for E is all its attributes. • 3) No relationship involves E more than once. • Replacing E: • 1) If there is a many-one relationship R from some entity • set F to E, then remove R and make the attributes of E • be attributes of F. Database Systems

  25. 4.2 Design Principles • 2) If there is a multiway relationship R with an arrow to E, • make the attributes of E be attributes of R and delete • the arc from R to E. • Tradeoff between using a multiway relationship and using a connecting entity set • Example • More studios • (See Fig. 4.13) Database Systems

  26. 4.2 Design Principles Database Systems

  27. 4.3 Constraints in the E/R Model • 4.3.1 Keys in the E/R Model • Every entity set must have a key. • There can be more than one possible key for an entity set. • When an entity set is involved in an isa-hierarchy, we require that the root entity set have all the attributes needed for a key, and that the key for each entity is found from its component in the root entity set. • 4.3.2 Representing Keys in the E/R Model • Example • (See Fig. 4.17) Database Systems

  28. 4.3 Constraints in the E/R Model Database Systems

  29. 4.3 Constraints in the E/R Model • 4.3.3 Referential Integrity • A value appearing in one context must also appear in another. • e.g., relationship Owns from Movies to Studios • Example • (See Fig. 4.18) • 4.3.4 Degree Constraints • A bounding number to the edges that connect a relationship to an entity set • Example • (See Fig. 4.19) Database Systems

  30. 4.3 Constraints in the E/R Model Database Systems

  31. 4.3 Constraints in the E/R Model Database Systems

  32. 4.4 Weak Entity Sets • It is possible for an entity set’s key to be composed of attributes, some or all of which belong to another entity set.. • 4.4.1 Causes of Weak Entity Sets • Two principal reasons: • 1) A hierarchy based on classifications unrelated to the • “isa hierarchy” • 2) The connecting entity sets • Example • key: (Studios)name+(Crews)number • (See Fig. 4.20) Database Systems

  33. 4.4 Weak Entity Sets Database Systems

  34. 4.4 Weak Entity Sets • key: (Genus)name+(Species)name • (See Fig. 4.21) • key: (Stars)name+(Studios)name+(Movies)(title+year) • (See Fig. 4.22) • 4.4.2 Requirements for Weak Entity Sets • If E is a weak entity set then its key consists of: • 1) zero or more of its own attributes, and • 2) key attributes from entity sets that are reached by • certain many-one relationships from E to other entity • sets, called supporting relationships for E. Database Systems

  35. 4.4 Weak Entity Sets Database Systems

  36. 4.4 Weak Entity Sets Database Systems

  37. 4.4 Weak Entity Sets • In order for R to be a supporting relationship for E, the following conditions must be obeyed: • 1) R must be a binary, many-one relationship from E to F. • 2) R must have referential integrity from E to F. • 3) The attributes that F supplies for the key of E must be • key attributes of F. • 4) If F is itself weak, then some or all of the key attributes • of F supplied to E will be key attributes of one or • more entity sets G to which F is connected by a • supporting relationship. Database Systems

  38. 4.4 Weak Entity Sets • 5) If there are several different supporting relationships • from E to F, then each relationship is used to supply a • copy of the key attributes of F to help form the key of E. • 4.4.3 Weak Entity Set Notation • If an entity set is weak, it will be shown as a rectangle with a double border. • Its supporting many-one relationships will be shown as diamonds with a double border. • If an entity set supplies any attributes for its own key, then those attributes will be underlined. Database Systems

  39. 4.4 Weak Entity Sets • It is possible for there to be many-one relationships from a weak entity set that are not supporting relationships, and therefore do not get a double diamond. • e.g., relationship: Studio-of • (Each movie has a unique owning studio, determined by • the many-one relationship from Movies to Studios.) Database Systems

  40. 4.5 From E/R Diagrams to Relational Designs • Converting an E/R design to a relational database schema: • 1) Turn each entity set into a relation with the same set of • attributes, and • 2) Replace a relationship by a relation whose attributes • are the keys for the connected entity sets. • Several special situations: • 1) Weak entity sets cannot be translated straightforwardly • to relations. • 2) “Isa” relationships and subclasses require careful • treatment. Database Systems

  41. 4.5 From E/R Diagrams to Relational Designs • 3) Sometimes, we do well to combine two relations, • especially the relation for an entity set E and the • relation that comes from a many-one relationship from • E to some other entity set. • 4.5.1 From Entity Sets to Relations • Example • (See Fig. 4.23) • 4.5.2 From E/R Relationships to Relations • Relationships in the E/R model are also represented by relations. Database Systems

  42. 4.5 From E/R Diagrams to Relational Designs Database Systems

  43. 4.5 From E/R Diagrams to Relational Designs • 1) For each entity set involved in relationship R, we take • its key attribute or attributes as part of the schema • of the relation for R. • 2) If the relationship has attributes, then these are also • attributes of relation R. • Example • (See Fig. 4.24 and Fig. 4.25) • Key of Contracts: starName+title+year+studioOfStar • +producingStudio Database Systems

  44. 4.5 From E/R Diagrams to Relational Designs Database Systems

  45. 4.5 From E/R Diagrams to Relational Designs Database Systems

  46. 4.5 From E/R Diagrams to Relational Designs • 4.5.3 Combining Relations • One common situation occurs when there is an entity set E with a many-one relationship R from E to F. • The relations E and R can be combined into one relation with a schema consisting of: • 1) All attributes of E • 2) The key attributes of F • 3) Any attributes belonging to relationship R • Example • (See Fig. 4.26) Database Systems

  47. 4.5 From E/R Diagrams to Relational Designs Database Systems

  48. 4.5 From E/R Diagrams to Relational Designs • But not for a many-many relationship • Example • (See Fig. 4.27) • 4.5.4 Handling Weak Entity Sets • Three things for weak entity sets: • 1) The relation for the weak entity set W itself must • include not only the attributes of W but also the key • attributes of the supporting entity sets. Database Systems

  49. 4.5 From E/R Diagrams to Relational Designs Database Systems

More Related