1 / 68

Entity-Relationship Model

Entity-Relationship Model. E-R Diagrams Class hierarchies Weak entity sets. Purpose of E/R Model. The E/R model allows us to sketch the design of a database informally. Designs are pictures called entity-relationship diagrams .

inoke
Download Presentation

Entity-Relationship Model

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. Entity-Relationship Model E-R Diagrams Class hierarchies Weak entity sets

  2. Purpose of E/R Model • The E/R model allows us to sketch the design of a database informally. • Designs are pictures called entity-relationship diagrams. • convert E/R diagrams to real implementations like relational databases exist.

  3. Entity Sets • Entity = “thing” or object. • Entity set = collection of similar entities. • Attribute = property of an entity set. • Generally, all entities in a set have the same properties. • Attributes are simple values, e.g. integers or character strings.

  4. Phone# name customer Bar Attributes Types • Single-valued attribute • Multi-valued attribute

  5. Date of birth customer Attributes Types,cont… • Derived attribute: the value of this attribute is derived from the value of other related attribute Example: Date of birth and Age Age

  6. E/R Diagrams • In an entity-relationship diagram, each entity set is represented by a rectangle. • Each attribute of an entity set is represented by an oval or ellipse

  7. name manf Beers Example • Entity set Beers has two attributes, name and manf (manufacturer). • Each Beer entity has values for these two attributes, e.g. (Bud, Anheuser-Busch)

  8. Relationships • A relationship connects two or more entity sets. • It is represented by a diamond, with lines to each of the entity sets involved. • Most relationship are Binary.

  9. name addr name manf Bars Beers Sells Bars sell some beers. license Drinkers like some beers. Frequents Likes Drinkers frequent some bars. Drinkers name addr Example

  10. Relationship Set • entity set: is the set of entities that belong to it. • Example: the set of all bars in our database. • Relationship set is lists of related entities, one from each of the related entity sets.

  11. Example • For the relationship Sells, we might have a relationship set like: Bar Beer Joe’s Bar Bud Joe’s Bar Miller Sue’s Bar Bud Sue’s Bar Pete’s Ale Sue’s Bar Bud Lite

  12. Multiway Relationships • Sometimes, we need a relationship that connects more than two entity sets. • Suppose that drinkers will only drink certain beers at certain bars. • Our three binary relationships Likes, Sells, and Frequents do not allow us to make this distinction. • But a 3-way (ternary) relationship would.

  13. Example name addr name manf Bars Beers license Preferences Drinkers name addr

  14. Disadvantages of ternary Relationship • Increase complexity of system • Some times it is not possible to translate constraints

  15. A Typical Relationship Set Bar Drinker Beer Joe’s Bar Ann Miller Sue’s Bar Ann Bud Sue’s Bar Ann Pete’s Ale Joe’s Bar Bob Bud Joe’s Bar Bob Miller Joe’s Bar Cal Miller Sue’s Bar Cal Bud Lite

  16. Types of Relationship? • One-to-One relationship • One-to-Many relationship • Many-to-One relationship • Many-to-Many relationship

  17. One-One Relationships • Each entity of either entity set is related to at most one entity of the other set. • Example: Relationship Best-sellerbetween entity sets Manfs (manufacturer) and Beers. • A beer cannot be made by more than one manufacturer, and no manufacturer can have more than one best-seller.

  18. Many-One Relationships • Some binary relationships are many -one from one entity set to another. • Each entity of the first set is connected to at most one entity of the second set. • But an entity of the second set can be connected to zero, one, or many entities of the first set.

  19. Example • Favorite, from Drinkers to Beers is many-one. • A drinker has at most one favorite beer. • But a beer can be the favorite of any number of drinkers, including zero.

  20. Many-Many Relationships • Sells between Bars and Beers. • In a many-many relationship, an entity of either set can be connected to many entities of the other set. • E.g., a bar sells many beers; a beer is sold by many bars.

  21. Representing “Multiplicity” • Show a many-one relationship by an arrow entering the “one” side. • Show a one-one relationship by arrows entering both entity sets.

  22. Example : many-to-one Likes Drinkers Beers Favorite

  23. Example: one-to-one • Consider Best-seller between Manfs and Beers. Best- seller Manfs Beers

  24. Attributes on Relationships • Sometimes it is useful to attach an attribute to a relationship especially in many-to-many relationship . Sells Bars Beers price

  25. Equivalent Diagrams Without Attributes on Relationships • Create an entity set representing values of the attribute. • Make that entity set participate in the relationship.

  26. Example Sells Bars Beers Prices price

  27. Attributes on Relationships Attributes on Relationships depends on the type of relationship. In one-to-one and one-to-many relationship the attributes can be associated with one of the participating entity sets rather than with the relationship set, while in many-to-many the attribute must be associated with relationship set.

  28. Attributes on Relationships: one-to-many Example: one -to-many (one customer may have several accounts but each account is held by only one customer). In this case , access time [when the customer last access that account] be associated with account entity customer account Ahmad Amjad Khaled deposit account customer 28 Access time

  29. Attributes on Relationships: one -to-one The relationship attribute can be associated with either one of the participating entity set. In this case , access time [when the customer last access that account] be associated with customer or account entity.

  30. Attributes on Relationships many -to-many The relationship attribute must be associated with the relationship set. In this case , access time [when the customer last access that account] must be associated with depositor relationship set, because if it was an attribute of account , we can’t determine which customer last access the joint account. deposit account customer 30 Access time

  31. Many-to-many • if access time attribute was an attribute of account we can’t determine which customer last access the joint account, so the attribute must be on the relationship set. customer account Ahmad Amjad Khaled • if access time attribute was an attribute of customer we can’t determine for which account is the last access time, so the attribute must be on the relationship set.. customer account Ahmad – 24/4/2007 Amjad – 11/5/2006 Khaled – 25/7/2007

  32. E-R diagram • E-R diagram can show the number of times each entity participate in relationship by associate the minimum and maximum times that shown in form L….H . • L = minimum H= maximum • The customer can have 0 or more loan and each loan must have exactly one associated customer. • 0 …* 1…1 borrower loan customer

  33. Keys • A key is a set of attributes for one entity set such that no two entities in this set agree on all the attributes of the key. • It is allowed for two entities to agree on some, but not all, of the key attributes. • We must designate a key for every entity set.

  34. Keys in E/R Diagrams • Underline the key attribute(s). • In an Isa hierarchy, only the root entity set has a key, and it must serve as the key for all entities in the hierarchy.

  35. Example: name is Key for Beers Beers name manf isa Ales color

  36. Example: a Multi-attribute Keyor super-key dept number hours room Courses • Note that hours and roomcould also serve as a • key, but we must select only one key(primary key) • -Candidate key : all possible key • - We want always minimal super-key

  37. Weak Entity Sets • is an entity that cannot be uniquely identified by its own attributes alone • therefore, it must use a foreign key in conjunction with its attributes to create a Primary key. • The foreign key is a primary key of one relation but it is an attribute in other relation

  38. Example • name is almost a key for football players, but there might be two with the same name. • number is certainly not a key, since players on two teams could have the same number. • But number, together with the Team-name related to the player by Plays-on should be unique.

  39. Weak Entity-Set Rules • The key for a weak entity set is its own underlined attributes and the keys for the supporting entity sets. • E.g., player-number and team-name is a key for Players in the previous example.

  40. In E/R Diagrams name number name Plays- on Players Teams • Double diamond for supportingmany-one relationship • between weak entity and dependent entity. • Double rectangle for the weak entity set.

  41. Don’t Overuse Weak Entity Sets • Beginning database designers often doubt that anything could be a key by itself. • They make all entity sets weak, supported by all other entity sets to which they are linked. • In reality, we usually create unique ID’s for entity sets.

  42. When Do We Need Weak Entity Sets? • When there is no capability of creating unique ID’s.

  43. Extended E-R Features • 1- specialization • 2-Aggregation

  44. Extended E-R Features1- specialization Specialization: is a process of defining subgroup within an entity set Top-down level Beers name manf High Level [super class] isa Ales XYZ color Low Level [subclass] Taste

  45. Another example Person city name High Level [super class] isa salary customer employee id Low Level [subclass] C-id

  46. Subclasses • Subclass = special case = more properties. • Example: Ales are a kind of beer. • Not every beer is an ales, but some are. • Let us suppose that in addition to all the properties (attributes and relationships) of beers, ales also have the attribute color.

  47. Subclasses in E/R Diagrams • Isa triangles indicate the subclass relationship. • Point to the superclass.

  48. E/R Vs. Object-Oriented Subclasses • Subclasses inherit properties from superclasses.

  49. Extended E-R Features2-Aggregation • This E-R diagram can’t express relation across relationship. job Works on branch employee manages manager

  50. Extended E-R Features-solution[Aggregation] • Is an abstraction through which relationships are treated as higher-level entity. work job Works on branch employee manages manager

More Related