e r diagrams converting e r diagrams to relations db
play

E/R Diagrams Converting E/R Diagrams to Relations DB design is - PowerPoint PPT Presentation

E/R Diagrams Converting E/R Diagrams to Relations DB design is a serious and possibly complex business. A client may know they want a database, but they don t know what they want in it or how it should look. E/R


  1. E/R Diagrams � Converting E/R Diagrams to Relations �

  2.  DB design is a serious and possibly complex business. �  A client may know they want a database, but they don ʼ t know what they want in it or how it should look. �  E/R diagrams are used as a first step to come up with a database schema �  Pin down initial ideas in a high-level structure (the E/R diagram) �  Sketching the key DB components is an efficient way to develop a working database. �  It ʼ s much better to start with a good design, rather than try to repair a poor design. �  So thought at this point will pay dividends later. �

  3.  The E/R model allows us to sketch database schema designs. �  Shows the logical structure of the database �  Includes some constraints �  Designs are pictures called entity-relationship diagrams . �  Roughly: made up of � things, called entity sets, � 1. attributes, or properties of entities, � 2. and relationships between entities � 3.  Later: convert E/R designs to relational DB designs. �

  4. name manf name addr Sells Beers Bars license

  5.  Entity = “thing” or object. �  Entity set = collection of similar entities �  Similar to a class in object-oriented languages. �  E.g. an employee is an entity, and the set of all employees constitutes an entity set �  An entity set can be thought of as an instance template �  An E/R diagram doesn ʼ t have associated instances �

  6.  Attribute = property of (the entities of) an entity set. �  Attributes are simple values �  E.g. integers or character strings, not structs, sets, etc. �

  7.  In an entity-relationship diagram: �  Entity set = rectangle. �  Attribute = oval, with a line to the rectangle representing its entity set. �

  8. name manf Beers  Entity set Beers has two attributes, name and manf (manufacturer). �  Each Beers entity has values for these two attributes, e.g. (Molsen, G.I.) �

  9.  A relationship connects two or more entity sets. �  It is represented by a diamond, with lines to each of the entity sets involved. �

  10. name addr name manf Bars Sells Beers Bars sell some � beers. � license

  11. name addr name manf Bars Sells Beers Bars sell some � beers. � license Customers like � Likes some beers. � Cust. name addr

  12. name addr name manf Bars Sells Beers Bars sell some � beers. � license Customers like � Frequents Likes some beers. � Customers frequent � some bars. � Cust. name addr

  13.  The current “value” of an entity set is the set of entities that belong to it. �  Example: the set of all bars in our database. �  The “value” of a relationship is a relationship set , a set of tuples with one component for each related entity set. �

  14.  For the relationship Sells, we might think of a relationship set like: � Bar Beer Joe ʼ s Bar � Export � Joe ʼ s Bar � G.I. � Sue ʼ s Bar � Export � Sue ʼ s Bar � Pete ʼ s Ale � Sue ʼ s Bar � Canadian �  A relationship set can be thought of as an instance of a relationship �

  15.  Sometimes, we need a relationship that connects more than two entity sets. �  Suppose that Customers 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 relationship would. �

  16. name addr name manf Bars Beers license Preferences Customers name addr

  17. Bar � � Customer � Beer � Joe ʼ s Bar � Ann � � G.I. � Sue ʼ s Bar � Ann � � Export � Sue ʼ s Bar � Ann � � Pete ʼ s Ale � Joe ʼ s Bar � Bob � � Export � Joe ʼ s Bar � Bob � � G.I. � Joe ʼ s Bar � Cal � � G.I. � Sue ʼ s Bar � Cal � � Canadian �

  18.  In some cases, relationships between entities are unrestricted �  In other cases, there may be functional restrictions in one or both directions of a (binary) relationship �

  19.  Focus: Binary relationships, such as Sells between Bars and Beers. �  In a many-many relationship, an entity of either set can be connected to several entities of the other set. �  E.g., a bar sells many beers; a beer is sold by many bars. �

  20. many-many

  21.  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. �  So we have a (partial) functional relationship �  But an entity of the second set can be connected to zero, one, or many entities of the first set. �

  22. many-one

  23.  Favorite, from Customers to Beers is many-one. �  A customer has at most one favorite beer. �  But a beer can be the favorite of any number of customers, including zero. �

  24.  In a one-one relationship, each entity of either entity set is related to at most one entity of the other set. �  Example: Relationship Best-seller between entity sets Manfs (manufacturer) and Beers. �  A beer cannot be made by more than one manufacturer �  No manufacturer can have more than one best-seller (assume no ties). �

  25. one-one

  26.  Show a many-one relationship by an arrow pointing to the “one” side. �  Show a one-one relationship by arrows pointing to both entity sets. �  Rounded arrow = “exactly one,” i.e., each entity of the first set is related to exactly one entity of the target set. �  Aside: Other texts may use slightly different notation �

  27. Customers Beers Likes Notice: two relationships � Favorite connect the same entity � sets, but are different. �

  28.  Consider Best-seller between Manfs and Beers. �  Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfs would be inappropriate. �  But a beer manufacturer has to have a best-seller. �

  29. Best- Manfs Beers seller A beer is the best- � A manufacturer has � seller for 0 or 1 � exactly one best � manufacturer. � seller. �

  30.  Sometimes it is useful to attach an attribute to a relationship. �  Think of this attribute as a property of tuples in the relationship set. �

  31. Bars Beers Sells price Price is a function of both the bar and the beer, � not of one alone. �

  32.  It ʼ s possible to create a E/R diagram without atributes on relationships. �  Create an entity set representing values of the attribute. �  Have that entity set participate in the relationship. �

  33. Bars Beers Sells Note convention: arrow � from multiway relationship � = “all other entity sets � Prices together determine a � unique one of these.” � -> Again, other texts may price use different notation. �

  34.  Sometimes an entity set appears more than once in a relationship. �  Label the edges between the relationship and the entity set with names called roles . �

  35. Relationship Set Husband Wife Bob Ann Joe Sue Married … … husband wife Customers

  36. Relationship Set Friend1 Friend2 Bob Ann Joe Sue Friends Ann Bob Joe Moe 1 2 … … Customers

  37.  Subclass = specialization of an entity �  A subclass will usually have fewer entities … �  … but additional properties. �  Example: Ales are a kind of beer. �  Not every beer is an ale, but some are. �  Suppose that in addition to all the properties (attributes and relationships) of beers, ales also have the attribute colour. �

  38.  Assume subclasses form a tree. �  I.e., no multiple inheritance. �  Isa triangles indicate the superclass/subclass relationship. �  Point to the superclass. �

  39. name manf Beers isa Ales colour

  40.  In OO, objects are in one class only. �  Subclasses inherit from superclasses. �  In contrast, E/R entities have representatives (i.e. tuples) in all subclasses to which they belong. �  Rule: if entity e is represented in a subclass, then e is represented in the superclass (and recursively up the tree). �  Think in terms of a database instance: �  If entity e is in a subclass, it has values for each attribute of that class �  But it must also have values for each attribute of each superclass �

  41. name manf Beers Pete’s Ale isa Ales colour

  42.  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. �  Two entities may agree on some, but not all, of the key attributes. �  Thus keys uniquely identify entities �  We must designate a key for every entity set. �

  43.  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. �

  44. name manf Beers isa Ales colour

  45. dept hours room number Courses  Note that hours and room could also serve as a � key, but we must select only one key. �  Later: dept + number will be called a primary key. �

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend