Example: dental hygienist

Entity-Relationship Model - Stanford University

1 Entity-Relationship ModelE/R DiagramsWeak Entity SetsConverting E/R Diagrams to Relations2 Purpose of E/R Model The E/R Model allows us to sketch database schema designs. Includes some constraints, but not operations. Designs are pictures called Entity-Relationship diagrams. Later: convert E/R designs to relational DB for E/R Design is a serious business. The boss knows they want a database, but they don t know what they want in it. Sketching the key components is an efficient way to develop a working Sets Entity= thing or object . Entity set= collection of similar entities.

Entity= “thing” or object. Entity set= collection of similar entities. Similar to a class in object-oriented languages. Attribute= property of (the entities of) an entity set. Attributes are simple values, e.g. integers or character strings, not structs, sets, etc.

Tags:

  Model, Relationship, Object, Relationship model

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Entity-Relationship Model - Stanford University

1 1 Entity-Relationship ModelE/R DiagramsWeak Entity SetsConverting E/R Diagrams to Relations2 Purpose of E/R Model The E/R Model allows us to sketch database schema designs. Includes some constraints, but not operations. Designs are pictures called Entity-Relationship diagrams. Later: convert E/R designs to relational DB for E/R Design is a serious business. The boss knows they want a database, but they don t know what they want in it. Sketching the key components is an efficient way to develop a working Sets Entity= thing or object . Entity set= collection of similar entities.

2 Similar to a class in object -oriented languages. Attribute= property of (the entities of) an entity set. Attributes are simple values, integers or character strings, not structs, sets, Diagrams In an Entity-Relationship diagram: Entity set = rectangle. Attribute = oval, with a line to the rectangle representing its entity : Entity set Beershas two attributes, nameand manf(manufacturer). Each Beersentity has values for these two attributes, (Bud, Anheuser-Busch)Beersnamemanf7 Relationships A relationshipconnects two or more entity sets. It is represented by a diamond, with lines to each of the entity sets : RelationshipsDrinkersaddrnameBeersmanfna meBarsnamelicenseaddrNote:license =beer, full,noneSellsBars sell likesome frequentsome Set The current value of an entity set is the set of entities that belong to it.

3 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 : relationship Set For the relationship Sells, we might have a relationship set like:BarBeerJoe s Bar BudJoe s Bar MillerSue s Bar BudSue s Bar Pete s AleSue s Bar Bud Lite11 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 Frequentsdo not allow us to make this distinction.

4 But a 3-way relationship : 3-Way RelationshipBarsBeersDrinkersnamenameadd rmanfnameaddrlicensePreferences13A Typical relationship SetBarDrinker BeerJoe s Bar AnnMillerSue s Bar AnnBudSue s Bar AnnPete s AleJoe s Bar BobBudJoe s Bar BobMillerJoe s Bar CalMillerSue s Bar CalBud Lite14 Many-Many Relationships Focus: binaryrelationships, such as Sellsbetween Barsand Beers. In a many-manyrelationship, an entity of either set can be connected to many entities of the other set. , a bar sells many beers; a beer is sold by many Pictures:many-many16 Many-One Relationships Some binary relationships are many -onefrom one entity set to another.

5 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 Pictures:many-one18 Example: Many-One relationship Favorite, from Drinkersto Beersis many-one. A drinker has at most one favorite beer. But a beer can be the favorite of any number of drinkers, including Relationships In a one-onerelationship, 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.

6 A beer cannot be made by more than one manufacturer, and no manufacturer can have more than one best-seller (assume no ties).20In Pictures:one-one21 Representing Multiplicity Show a many-one relationship by an arrow entering the one side. Remember: Like a functional dependency. Show a one-one relationship by arrows entering both entity sets. Rounded arrow= exactly one, , each entity of the first set is related to exactly one entity of the target : Many-One RelationshipDrinkersBeersLikesFavoriteNo tice: two relationshipsconnect the same entitysets, but are : One-One relationship Consider Best-sellerbetween Manfsand Beers.

7 Some beers are not the best-seller of any manufacturer, so a rounded arrow to Manfswould be inappropriate. But a beer manufacturer has to have a the E/R DiagramManfsBeersBest-sellerA manufacturer hasexactly one beer is the best-seller for 0 or on Relationships Sometimes it is useful to attach an attribute to a relationship . Think of this attribute as a property of tuples in the relationship : Attribute on RelationshipBarsBeersSellspricePrice is a function of both the bar and the beer,not of one Diagrams Without Attributes on Relationships Create an entity set representing values of the attribute.

8 Make that entity set participate in the : Removing an Attribute from a RelationshipBarsBeersSellspricePricesNot e convention: arrowfrom multiway relationship = all other entity setstogether determine aunique one of these. 29 Roles Sometimes an entity set appears more than once in a relationship . Label the edges between the relationship and the entity set with names called : RolesDrinkersMarriedhusbandwifeRelations hip SetHusband : RolesDrinkersBuddies12 relationship SetBuddy1 Subclass= special case = fewer entities = more properties. Example: Ales are a kind of beer.

9 Not every beer is an ale, but some are. Let us suppose that in addition to all the properties(attributes and relationships) of beers, ales also have the attribute in E/R Diagrams Assume subclasses form a tree. , no multiple inheritance. Isa triangles indicate the subclass relationship . Point to the : SubclassesBeersAlesisanamemanfcolor35E/R Vs. object -Oriented Subclasses In OO, objects are in one class only. Subclasses inherit from superclasses. In contrast, E/R entities have representativesin all subclasses to which they belong. Rule: if entity eis represented in a subclass, then eis represented in the superclass (and recursively up the tree).

10 36 Example: Representatives of EntitiesBeersAlesisanamemanfcolorPete s Ale37 Keys A keyis 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 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 : nameis Key for BeersBeersAlesisanamemanfcolor40 Example: a Multi-attribute KeyCoursesdeptnumberhoursroom Note that hoursand roomcould also serve as akey, but we must select only one Entity Sets Occasionally, entities of an entity set need help to identify them uniquely.


Related search queries