SlideShare a Scribd company logo
The E-R Model Prof. Sin-Min Lee  Department of Computer Science CS 157A Lecture 4
 
 
 
 
Entity-Relationship (E-R) Model COURSE # CTITILE PROF SCHED ROOM COURSE ENROLL STUDENT STUID SNAME MAJOR CREDITS GRADE
Class Hierarchies Employees ssn name lot ISA Hourly Emps Contract Emps Hourly wage Hours worked contractid * Sometimes it’s natural to classify the entities in an entity set into subclass, then we will use Class Hierarchies.
Aggregation name ssn lot Employees monitors until since Sponsors Department Projects pid Started-on pbudget dname did budget * A relationship set is an association between entity sets.  Sometimes we have to model a relationship between a collection of entities and relationships, then we need to use  aggregation .
Conceptual design using the ER model Should a concept be modeled as an entity or an attribute ? Should a concept be modeled as an entity or a relationship ? What are the relationships ? Should we use binary or ternary relationships ? Should we use aggregation ?
UNARY RELATIONSHIP Unary relationship  : is an associate of 1 entity set. *  Note  : an entity set  is a group of related entities. Student * Entity set =  * Relation =  Dr. Lee * Attribute =
BINARY RELATIONSHIP Binary relationship  : is an associate of 2 entities sets . Employees Works_In Department * Entity set = * Relation =  * Attribute = ssn name lot did budget dname
TERNARY RELATIONSHIP Works_In Employees Department Locations Ternary relationship  : is an associate of 3 entities sets . * Entity set =  * Relation  =  ssn name lot did dname budget cap add * Attribute =
QUARTERY  RELATIONSHIP Employees Works_In Locations Department Product Quartery relationship  : is an associate of 4 entities sets. * Entity set = * Relation =  * Attribute =
 
Additional features of the ER model In the ER model allow us to draw important distinctions about the data. One of the features of the ER model is : Key Constraints Note  :  A key constraints is also known as Primary key. A primary key is a candidate key selected to  uniquely identify all other attribute values in  any given row, can not contain null entries.
An example of  Key Constraints  on  Manage Manages Department Employees ssn name lot Since dname did budget ssn = Social Security Number. did =  Department  id.
 
Weak Entities A weak entity  : is an entity of which is existence depends on  other entities. Policy Department Employees ssn name lot cost Pname --------- age
 
 
Entity versus Attribute Works-In2 Department Employees ssn name lot from dname did budget to *  Entity set  = * Relation =  *  Attribute  =
Entity versus Relationship Manages Department Employees ssn name apptnum did budget dname Mgr-Appts lot since dbudget
Binary versus Ternary Relationship Covers Dependents Employees ssn name Pname --------- age Policies lot policyid cost
Using a Ternary Relationship instead of Aggregation Sponsors Departments Projects pid Started-on did budget pbudget dname Employees name ssn lot
ONE TO MANY RELATIONSHIP   customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
MANY TO ONE RELATIONSHIP   customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
ONE TO ONE RELATIONSHIP   customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
E-R Diagram with Composite, Multivalued, and Derived Attributes Customer date-of-birth phone-number name customer-id first-name age last-name middle-name zip-code state city address street Street-number apartment-number street-name
WEAK ENTITY SETS An entity set may not have sufficient attributes to form a primary key.  Such  an entity set is termed a  weak entity set .  An entity set that has a primary key is termed a  strong entity set . For a weak entity set to be meaningful, it must be associated with another entity set, called the  identifying  or  owner entity set .  The relationship associating the weak entity set with the identifying entity set is called the  identifying relationship . The identifying relationship is  many to one  from the weak entity set to the identifying entity set, and the participation of the weak entity set in the relationship is  total .
DISCRIMINATOR The  discriminator  of a weak entity set is a set of attributes that allows this distinction to be made.  For example, the discriminator of a weak entity set payment is the attribute  payment-number , since, for each loan a payment number uniquely identifies one single payment for that loan.  The discriminator of a weak entity set is also called the  partial key  of the entity set. Note: although each payment entity is distinct, payments for different loans may share the same  payment-number .  Thus, payment entity set does not have a primary key; it is a weak entity set. The  primary key of a weak entity set  is formed by the primary key of the identifying entity set, plus the weak entity set’s discriminator.
E-R DIAGRAM WITH A WEAK ENTITY SET In a E-R diagrams, a  doubly outlined box  indicates a weak entity set, and a  doubly outlined diamond  indicates the corresponding identifying relationship.  We underline the discriminator of a weak entity set with a  dashed line . loan E-R diagram with a weak entity set loan-payment payment payment-date payment-amount payment-number amount loan-number
 
 
 
 
Entity/Relationship Model Diagrams to represent designs. Entity  like object, = “thing.” Entity set  like class = set of “similar” entities/objects. Attribute  = property of entities in an entity set, similar to fields of a struct. In diagrams, entity set    rectangle; attribute    oval. Students ID name phone height
Relationships Connect two or more entity sets. Represented by diamonds. Students Courses Taking
Relationship Set Think of the “value” of a relationship set as a table. One column for each of the connected entity sets. One row for each list of entities, one from each set, that are connected by the relationship. Students Courses Sally CS180 Sally CS111 Joe CS180 … …
Multiway Relationships Usually binary relationships (connecting two E.S.) suffice. However, there are some cases where three or more E.S. must be connected by one relationship. Example: relationship among students, courses, TA's (and graders). Possibly, this E/R diagram is OK: Students Courses Taking Assisting TA/Graders
Works in CS180, because each TA (or grader) is a TA of all students.  Connection student-TA is  only  via the course. But what if students were divided into sections, each headed by a TA? Then, a student in CS180 would be related to only one of the TA's for CS180.  Which one? Need a 3-way relationship to tell.
Students Courses TAs Ann CS180 Jan Sue CS180 Pat Bob CS180 Jan … … … Students Courses TAs Enrolls
Beers-Bars-Drinkers Example Our running example for the course. name addr license name manf name addr Beers Drinkers Bars Serves Frequents Likes
Multiplicity of Relationships Representation of Many-One E/R: arrow pointing to “one.” Rounded arrow = “exactly one.” Many-many Many-one One-one
Example: Drinkers Have Favorite Beers name addr license name manf name addr Beers Drinkers Bars Serves Frequents Likes Favorite
One-One Relationships Put arrows in both directions. Design Issue: Is the rounded arrow justified? Design Issue: Here, manufacturer is an E.S. In earlier diagrams it is an attribute. Which is right? Manfs Beers Best- seller
Attributes on Relationships Shorthand for 3-way relationship: Bars Beers Sells price Bars Beers Sells price Prices
A true 3-way relationship. Price depends jointly on beer and bar. Notice arrow convention for multiway relationships: “all other E.S. determine one of these.” Not sufficiently general to express any possibility. However, if price, say, depended only on the beer, then we could use two 2-way relationships: price-beer and beer-bar. Or better: just make price an attribute of beer.
Converting Multiway to 2-Way Baroque in E/R, but necessary in certain “object-oriented” models. Create a new connecting E.S. to represent rows of a relationship set. E.g., (Joe's Bar, Bud, $2.50) for the  Sells  relationship. Many-one relationships from the connecting E.S.  to the others. Bars Beers The- Bar Price The- Beer The- Price BBP
Roles Sometimes an E.S. participates more than once in a relationship. Label edges with  roles  to distinguish. Husband Wife d 1 d 2 d 3 d 4 … … Drinkers Married husband wife
Notice  Buddies  is symmetric, Married not. No way to say “symmetric” in E/R. Design Question Should we replace  husband  and  wife  by one relationship  spouse ? Buddy1 Buddy2 d 1 d 2 d 1 d 3 d 2 d 1 d 2 d 4 … … Drinkers Buddies 1 2
More Design Issues 1. Subclasses. 2. Keys. 3. Weak entity sets. (Next class.)
Subclasses Subclass = special case = fewer entities = more properties. Example: Ales are a kind of beer.  In addition to the  properties  (= attributes and relationships) of beers, there is a “color” attribute for ales.
E/R Subclasses Assume subclasses form a tree (no multiple inheritance). isa  triangles indicate the subclass relation. name manf Beers Ales color isa
Different Subclass Viewpoints 1.  E/R viewpoint : An entity has a  component  in each entity set to which it logically belongs. Its properties are the union of the properties of these E.S. 2. Contrasts with  object-oriented viewpoint : An object (entity) belongs to exactly one class. It  inherits  properties of its superclasses. name manf Beers Ales color isa Pete’s Ale
Multiple Inheritance Theoretically, an E.S. could be a subclass of several other entity sets. name manf Beers name manf Wines Grape Beers isa isa
Problems How should conflicts be resolved? Example:  manf  means vintner for wines, bottler for beers. What does  manf  mean for “grape beers”? Need ad-hoc notation to resolve meanings. In practice, we shall assume a tree of entity sets connected by  isa , with all “isas” pointing from child to parent.
Keys A  key  is a set of attributes whose values can belong to at most one entity. In E/R model, every E.S. must have a key. It could have more than one key, but one set of attributes is the “designated” key. In E/R diagrams, you should underline all attributes of the designated key.
Example Suppose  name  is key for  Beers . Beer name is also key for ales. In general, key at root is key for all. name manf Beers Ales color isa
Example: A Multiattribute Key Possibly, the combination of hours + room also forms a key, but we have not designated it as such. dept room Courses number hours

More Related Content

What's hot (20)

PPT
Packet tracer
Imdad Ullah
 
PPTX
DBMS: Types of keys
Bharati Ugale
 
PPT
Entity relationship modelling
Dr. C.V. Suresh Babu
 
PPTX
File handling in Python
Megha V
 
PPTX
Introduction to object oriented language
farhan amjad
 
PPTX
Normal forms
Samuel Igbanogu
 
PPTX
Entity Relationship Modelling
Bhandari Nawaraj
 
PPTX
3 Level Architecture
Adeel Rasheed
 
PPTX
Introduction to SQL
Ehsan Hamzei
 
PPTX
Decomposition using Functional Dependency
Raj Naik
 
PPTX
IP addressing and Subnetting PPT
Pijush Kanti Das
 
PPT
Server configuration
Aisha Talat
 
PPT
MYSQL.ppt
webhostingguy
 
PPTX
System calls
Bernard Senam
 
PPTX
Pointers in c++
Rajat Busheheri
 
PPTX
E-R diagram in Database
Fatiha Qureshi
 
PPTX
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
PPT
Database Connection
John Joseph San Juan
 
PPTX
Variables in C++, data types in c++
Neeru Mittal
 
Packet tracer
Imdad Ullah
 
DBMS: Types of keys
Bharati Ugale
 
Entity relationship modelling
Dr. C.V. Suresh Babu
 
File handling in Python
Megha V
 
Introduction to object oriented language
farhan amjad
 
Normal forms
Samuel Igbanogu
 
Entity Relationship Modelling
Bhandari Nawaraj
 
3 Level Architecture
Adeel Rasheed
 
Introduction to SQL
Ehsan Hamzei
 
Decomposition using Functional Dependency
Raj Naik
 
IP addressing and Subnetting PPT
Pijush Kanti Das
 
Server configuration
Aisha Talat
 
MYSQL.ppt
webhostingguy
 
System calls
Bernard Senam
 
Pointers in c++
Rajat Busheheri
 
E-R diagram in Database
Fatiha Qureshi
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
Database Connection
John Joseph San Juan
 
Variables in C++, data types in c++
Neeru Mittal
 

Viewers also liked (8)

PPTX
Slide 6 er strong & weak entity
Visakh V
 
PPT
Entity Relationship Diagram2
sadeenedian08
 
PPT
dbms
royalrao85
 
PPT
Unit 02 dbms
anuragmbst
 
PPTX
Database Modeling Using Entity.. Weak And Strong Entity Types
aakanksha s
 
PPTX
How to Draw an Effective ER diagram
Tech_MX
 
PPTX
ER model to Relational model mapping
Shubham Saini
 
Slide 6 er strong & weak entity
Visakh V
 
Entity Relationship Diagram2
sadeenedian08
 
Unit 02 dbms
anuragmbst
 
Database Modeling Using Entity.. Weak And Strong Entity Types
aakanksha s
 
How to Draw an Effective ER diagram
Tech_MX
 
ER model to Relational model mapping
Shubham Saini
 
Ad

Similar to DBMS UNIT1 (20)

PPTX
Entityrelationshipmodel
Enes Bolfidan
 
PPT
Unit02 dbms
arnold 7490
 
PPT
Er Model Nandha&Mani
guest1e0229a
 
PPTX
ER MODEL
Rupali Rana
 
PPT
10287 lecture5(2)
Universitas Bina Darma Palembang
 
PPTX
entityrelationshipmodel.pptx
ThangamaniR3
 
PPTX
ECEG 4702-Class7-Entity-Relationship modeling.pptx
miftah88
 
PPTX
DBMS Unit-2_Final.pptx
parimala123
 
PPT
E R Model details.ppt
ShivareddyGangam
 
PPT
03 Ch3 Notes Revised
guest6f408c
 
PPTX
Basic building entity relationship model
ironman82715
 
PPT
dbms er model
Surya Swaroop
 
PPT
27 fcs157al3
CHANDRA BHUSHAN
 
PDF
ERD with complete knowledge
Asma Rasool
 
PPTX
Entity Relationship Model
Slideshare
 
PPTX
Er model
gagan bhattarai
 
PPTX
Entity Relationship Diagram – ER Diagram in DBMS.pptx
sukrithlal008
 
PPTX
DBMS Conceptual Design using ER Model.pptx
ssuser19199c
 
PDF
Lecture 2 database management system.pdf
samerelking3
 
Entityrelationshipmodel
Enes Bolfidan
 
Unit02 dbms
arnold 7490
 
Er Model Nandha&Mani
guest1e0229a
 
ER MODEL
Rupali Rana
 
entityrelationshipmodel.pptx
ThangamaniR3
 
ECEG 4702-Class7-Entity-Relationship modeling.pptx
miftah88
 
DBMS Unit-2_Final.pptx
parimala123
 
E R Model details.ppt
ShivareddyGangam
 
03 Ch3 Notes Revised
guest6f408c
 
Basic building entity relationship model
ironman82715
 
dbms er model
Surya Swaroop
 
27 fcs157al3
CHANDRA BHUSHAN
 
ERD with complete knowledge
Asma Rasool
 
Entity Relationship Model
Slideshare
 
Er model
gagan bhattarai
 
Entity Relationship Diagram – ER Diagram in DBMS.pptx
sukrithlal008
 
DBMS Conceptual Design using ER Model.pptx
ssuser19199c
 
Lecture 2 database management system.pdf
samerelking3
 
Ad

Recently uploaded (20)

PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 

DBMS UNIT1

  • 1. The E-R Model Prof. Sin-Min Lee Department of Computer Science CS 157A Lecture 4
  • 2.  
  • 3.  
  • 4.  
  • 5.  
  • 6. Entity-Relationship (E-R) Model COURSE # CTITILE PROF SCHED ROOM COURSE ENROLL STUDENT STUID SNAME MAJOR CREDITS GRADE
  • 7. Class Hierarchies Employees ssn name lot ISA Hourly Emps Contract Emps Hourly wage Hours worked contractid * Sometimes it’s natural to classify the entities in an entity set into subclass, then we will use Class Hierarchies.
  • 8. Aggregation name ssn lot Employees monitors until since Sponsors Department Projects pid Started-on pbudget dname did budget * A relationship set is an association between entity sets. Sometimes we have to model a relationship between a collection of entities and relationships, then we need to use aggregation .
  • 9. Conceptual design using the ER model Should a concept be modeled as an entity or an attribute ? Should a concept be modeled as an entity or a relationship ? What are the relationships ? Should we use binary or ternary relationships ? Should we use aggregation ?
  • 10. UNARY RELATIONSHIP Unary relationship : is an associate of 1 entity set. * Note : an entity set is a group of related entities. Student * Entity set = * Relation = Dr. Lee * Attribute =
  • 11. BINARY RELATIONSHIP Binary relationship : is an associate of 2 entities sets . Employees Works_In Department * Entity set = * Relation = * Attribute = ssn name lot did budget dname
  • 12. TERNARY RELATIONSHIP Works_In Employees Department Locations Ternary relationship : is an associate of 3 entities sets . * Entity set = * Relation = ssn name lot did dname budget cap add * Attribute =
  • 13. QUARTERY RELATIONSHIP Employees Works_In Locations Department Product Quartery relationship : is an associate of 4 entities sets. * Entity set = * Relation = * Attribute =
  • 14.  
  • 15. Additional features of the ER model In the ER model allow us to draw important distinctions about the data. One of the features of the ER model is : Key Constraints Note : A key constraints is also known as Primary key. A primary key is a candidate key selected to uniquely identify all other attribute values in any given row, can not contain null entries.
  • 16. An example of Key Constraints on Manage Manages Department Employees ssn name lot Since dname did budget ssn = Social Security Number. did = Department id.
  • 17.  
  • 18. Weak Entities A weak entity : is an entity of which is existence depends on other entities. Policy Department Employees ssn name lot cost Pname --------- age
  • 19.  
  • 20.  
  • 21. Entity versus Attribute Works-In2 Department Employees ssn name lot from dname did budget to * Entity set = * Relation = * Attribute =
  • 22. Entity versus Relationship Manages Department Employees ssn name apptnum did budget dname Mgr-Appts lot since dbudget
  • 23. Binary versus Ternary Relationship Covers Dependents Employees ssn name Pname --------- age Policies lot policyid cost
  • 24. Using a Ternary Relationship instead of Aggregation Sponsors Departments Projects pid Started-on did budget pbudget dname Employees name ssn lot
  • 25. ONE TO MANY RELATIONSHIP customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
  • 26. MANY TO ONE RELATIONSHIP customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
  • 27. ONE TO ONE RELATIONSHIP customer customer-name customer-city customer-id borrower customer-street loan loan-number amount
  • 28. E-R Diagram with Composite, Multivalued, and Derived Attributes Customer date-of-birth phone-number name customer-id first-name age last-name middle-name zip-code state city address street Street-number apartment-number street-name
  • 29. WEAK ENTITY SETS An entity set may not have sufficient attributes to form a primary key. Such an entity set is termed a weak entity set . An entity set that has a primary key is termed a strong entity set . For a weak entity set to be meaningful, it must be associated with another entity set, called the identifying or owner entity set . The relationship associating the weak entity set with the identifying entity set is called the identifying relationship . The identifying relationship is many to one from the weak entity set to the identifying entity set, and the participation of the weak entity set in the relationship is total .
  • 30. DISCRIMINATOR The discriminator of a weak entity set is a set of attributes that allows this distinction to be made. For example, the discriminator of a weak entity set payment is the attribute payment-number , since, for each loan a payment number uniquely identifies one single payment for that loan. The discriminator of a weak entity set is also called the partial key of the entity set. Note: although each payment entity is distinct, payments for different loans may share the same payment-number . Thus, payment entity set does not have a primary key; it is a weak entity set. The primary key of a weak entity set is formed by the primary key of the identifying entity set, plus the weak entity set’s discriminator.
  • 31. E-R DIAGRAM WITH A WEAK ENTITY SET In a E-R diagrams, a doubly outlined box indicates a weak entity set, and a doubly outlined diamond indicates the corresponding identifying relationship. We underline the discriminator of a weak entity set with a dashed line . loan E-R diagram with a weak entity set loan-payment payment payment-date payment-amount payment-number amount loan-number
  • 32.  
  • 33.  
  • 34.  
  • 35.  
  • 36. Entity/Relationship Model Diagrams to represent designs. Entity like object, = “thing.” Entity set like class = set of “similar” entities/objects. Attribute = property of entities in an entity set, similar to fields of a struct. In diagrams, entity set  rectangle; attribute  oval. Students ID name phone height
  • 37. Relationships Connect two or more entity sets. Represented by diamonds. Students Courses Taking
  • 38. Relationship Set Think of the “value” of a relationship set as a table. One column for each of the connected entity sets. One row for each list of entities, one from each set, that are connected by the relationship. Students Courses Sally CS180 Sally CS111 Joe CS180 … …
  • 39. Multiway Relationships Usually binary relationships (connecting two E.S.) suffice. However, there are some cases where three or more E.S. must be connected by one relationship. Example: relationship among students, courses, TA's (and graders). Possibly, this E/R diagram is OK: Students Courses Taking Assisting TA/Graders
  • 40. Works in CS180, because each TA (or grader) is a TA of all students. Connection student-TA is only via the course. But what if students were divided into sections, each headed by a TA? Then, a student in CS180 would be related to only one of the TA's for CS180. Which one? Need a 3-way relationship to tell.
  • 41. Students Courses TAs Ann CS180 Jan Sue CS180 Pat Bob CS180 Jan … … … Students Courses TAs Enrolls
  • 42. Beers-Bars-Drinkers Example Our running example for the course. name addr license name manf name addr Beers Drinkers Bars Serves Frequents Likes
  • 43. Multiplicity of Relationships Representation of Many-One E/R: arrow pointing to “one.” Rounded arrow = “exactly one.” Many-many Many-one One-one
  • 44. Example: Drinkers Have Favorite Beers name addr license name manf name addr Beers Drinkers Bars Serves Frequents Likes Favorite
  • 45. One-One Relationships Put arrows in both directions. Design Issue: Is the rounded arrow justified? Design Issue: Here, manufacturer is an E.S. In earlier diagrams it is an attribute. Which is right? Manfs Beers Best- seller
  • 46. Attributes on Relationships Shorthand for 3-way relationship: Bars Beers Sells price Bars Beers Sells price Prices
  • 47. A true 3-way relationship. Price depends jointly on beer and bar. Notice arrow convention for multiway relationships: “all other E.S. determine one of these.” Not sufficiently general to express any possibility. However, if price, say, depended only on the beer, then we could use two 2-way relationships: price-beer and beer-bar. Or better: just make price an attribute of beer.
  • 48. Converting Multiway to 2-Way Baroque in E/R, but necessary in certain “object-oriented” models. Create a new connecting E.S. to represent rows of a relationship set. E.g., (Joe's Bar, Bud, $2.50) for the Sells relationship. Many-one relationships from the connecting E.S. to the others. Bars Beers The- Bar Price The- Beer The- Price BBP
  • 49. Roles Sometimes an E.S. participates more than once in a relationship. Label edges with roles to distinguish. Husband Wife d 1 d 2 d 3 d 4 … … Drinkers Married husband wife
  • 50. Notice Buddies is symmetric, Married not. No way to say “symmetric” in E/R. Design Question Should we replace husband and wife by one relationship spouse ? Buddy1 Buddy2 d 1 d 2 d 1 d 3 d 2 d 1 d 2 d 4 … … Drinkers Buddies 1 2
  • 51. More Design Issues 1. Subclasses. 2. Keys. 3. Weak entity sets. (Next class.)
  • 52. Subclasses Subclass = special case = fewer entities = more properties. Example: Ales are a kind of beer. In addition to the properties (= attributes and relationships) of beers, there is a “color” attribute for ales.
  • 53. E/R Subclasses Assume subclasses form a tree (no multiple inheritance). isa triangles indicate the subclass relation. name manf Beers Ales color isa
  • 54. Different Subclass Viewpoints 1. E/R viewpoint : An entity has a component in each entity set to which it logically belongs. Its properties are the union of the properties of these E.S. 2. Contrasts with object-oriented viewpoint : An object (entity) belongs to exactly one class. It inherits properties of its superclasses. name manf Beers Ales color isa Pete’s Ale
  • 55. Multiple Inheritance Theoretically, an E.S. could be a subclass of several other entity sets. name manf Beers name manf Wines Grape Beers isa isa
  • 56. Problems How should conflicts be resolved? Example: manf means vintner for wines, bottler for beers. What does manf mean for “grape beers”? Need ad-hoc notation to resolve meanings. In practice, we shall assume a tree of entity sets connected by isa , with all “isas” pointing from child to parent.
  • 57. Keys A key is a set of attributes whose values can belong to at most one entity. In E/R model, every E.S. must have a key. It could have more than one key, but one set of attributes is the “designated” key. In E/R diagrams, you should underline all attributes of the designated key.
  • 58. Example Suppose name is key for Beers . Beer name is also key for ales. In general, key at root is key for all. name manf Beers Ales color isa
  • 59. Example: A Multiattribute Key Possibly, the combination of hours + room also forms a key, but we have not designated it as such. dept room Courses number hours