程序代写代做 graph C ER database Chapter 7: Entity-Relationship Model

Chapter 7: Entity-Relationship Model
■ Design Process
■ Modeling
■ Constraints
■ E-R Diagram
■ Design Issues
■ Weak Entity Sets
■ Extended E-R Features
■ Design of the Bank Database
■ Reduction to Relation Schemas
■ Database Design
■ UML
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.1 ©Silberschatz, Korth and Sudarshan

Design Phases
■ The initial phase of database design is to characterize fully the data needs of the prospective database users.
■ Next, the designer chooses a data model and, by applying the concepts of the chosen data model, translates these requirements into a conceptual schema of the database.
■ Afullydevelopedconceptualschemaalsoindicatesthe functional requirements of the enterprise. In a “specification of functional requirements”, users describe the kinds of operations (or transactions) that will be performed on the data.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.2 ©Silberschatz, Korth and Sudarshan

Design Phases (Cont.)
The process of moving from an abstract data model to the implementation of the database proceeds in two final design phases.
■ Logical Design – Deciding on the database schema. Database design requires that we find a “good” collection of relation schemas.
● Business decision – What attributes should we record in the database?
● Computer Science decision – What relation schemas should we have and how should the attributes be distributed among the various relation schemas?
■ Physical Design – Deciding on the physical layout of the database
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.3 ©Silberschatz, Korth and Sudarshan

Design Approaches
■ Entity Relationship Model (covered in this chapter)
● Models an enterprise as a collection of entities and
relationships
! Entity: a “thing” or “object” in the enterprise that is distinguishable from other objects
– Described by a set of attributes
! Relationship: an association among several entities
● Represented diagrammatically by an entity-relationship diagram:
■ Normalization Theory (Chapter 8)
● Formalize what designs are bad, and test for them
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.4 ©Silberschatz, Korth and Sudarshan

Outline of the ER Model
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.5 ©Silberschatz, Korth and Sudarshan

ER model — Database Modeling
■ The ER data mode was developed to facilitate database design by allowing specification of an enterprise schema that represents the overall logical structure of a database.
■ The ER model is very useful in mapping the meanings and interactions of real-world enterprises onto a conceptual schema. Because of this usefulness, many database-design tools draw on concepts from the ER model.
■ The ER data model employs three basic concepts: ● entitysets,
● relationshipsets,
● attributes.
■ The ER model also has an associated diagrammatic representation, the ER diagram, which can express the overall logical structure of a database graphically.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.6 ©Silberschatz, Korth and Sudarshan

Entity Sets
■ An entity is an object that exists and is distinguishable from other objects.
● Example: specific person, company, event, plant
■ An entity set is a set of entities of the same type that share the same
properties.
● Example:setofallpersons,companies,trees,holidays
■ An entity is represented by a set of attributes; i.e., descriptive properties possessed by all members of an entity set.
● Example:
instructor = (ID, name, street, city, salary )

course= (course_id, title, credits)
■ A subset of the attributes form a primary key of the entity set; i.e.,
uniquely identifiying each member of the set.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.7 ©Silberschatz, Korth and Sudarshan

Entity Sets instructor and student
instructor_ID instructor_name
student-ID student_name
76766
Crick
45565
Katz
10101
Srinivasan
98345
Kim
76543
Singh
22222
Einstein
98988
Tanaka
12345
Shankar
00128
Zhang
76543
Brown
76653
Aoi
23121
Chavez
44553
Peltier
instructor
student
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.8
©Silberschatz, Korth and Sudarshan

Relationship Sets
■ A relationship is an association among several entities
Example:

44553 (Peltier) advisor 22222 (Einstein) 

student entityrelationship set instructor entity
■ A relationship set is a mathematical relation among n ≥ 2
entities, each taken from entity sets
{(e1,e2,…en)|e1 ∈E1,e2 ∈ E2,…,en ∈ En}


where (e1, e2, …, en) is a relationship
● Example:
(44553,22222) ∈ advisor
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.9 ©Silberschatz, Korth and Sudarshan

76766
Crick
Relationship Set advisor
45565
98988
Tanaka
Katz
Shankar
12345
10101
Srinivasan
00128
Zhang
98345
Kim
76543
Brown
76543
Singh
76653
Aoi
22222
Einstein
23121
Chavez
44553
Peltier
instructor
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
student
7.10 ©Silberschatz, Korth and Sudarshan

Relationship Sets (Cont.)
■ Anattributecanalsobepropertyofarelationshipset.
■ For instance, the advisor relationship set between entity sets instructor and student may have the attribute date which tracks when the student started being associated with the advisor
76766
Crick
45565
Katz
10101
Srinivasan
98345
Kim
76543
Singh
22222
Einstein
98988
Tanaka
12345
Shankar
00128
Zhang
76543
Brown
76653
Aoi
23121
Chavez
44553
Peltier
3 May 2008 10 June 2007
12 June 2006 6 June 2009 30 June 2007 31 May 2007 4 May 2006
instructor
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
student
7.11 ©Silberschatz, Korth and Sudarshan

Degree of a Relationship Set
■ binary relationship
● involve two entity sets (or degree two).
● most relationship sets in a database system are binary.
■ Relationships between more than two entity sets are rare. Most relationships are binary. (More on this later.)
! Example: students work on research projects under the guidance of an instructor.
! relationship proj_guide is a ternary relationship between instructor, student, and project
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.12 ©Silberschatz, Korth and Sudarshan

Mapping Cardinality Constraints
■ Express the number of entities to which another entity can be associated via a relationship set.
■ Most useful in describing binary relationship sets.
■ For a binary relationship set the mapping cardinality
must be one of the following types: ● One to one
● One to many
● Many to one
● Many to many
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.13 ©Silberschatz, Korth and Sudarshan

Mapping Cardinalities
One to one One to many
Note: Some elements in A and B may not be mapped to any elements in the other set
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.14 ©Silberschatz, Korth and Sudarshan

Many to one
Many to many
Mapping Cardinalities
Note: Some elements in A and B may not be mapped to any
elements in the other set
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.15 ©Silberschatz, Korth and Sudarshan

Attributes
■ Anentityisrepresentedbyasetofattributes,thatisdescriptive properties possessed by all members of an entity set.
● Example:
instructor = (ID, name, street, city, salary )

course= (course_id, title, credits)
■ Domain – the set of permitted values for each attribute ■ Attributetypes:
● Simple and composite attributes.
● Single-valued and multivalued attributes
! Example: multivalued attribute: phone_numbers ● Derived attributes
! Can be computed from other attributes
! Example: age, given date_of_birth
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.16 ©Silberschatz, Korth and Sudarshan

composite attributes
first_name
component attributes
name
middle_initial
last_name
street
address
city state
postal_code
Composite Attributes
street_number street_name apartment_number
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.17 ©Silberschatz, Korth and Sudarshan

Keys
■ Asuperkeyofanentitysetisasetofoneormore attributes whose values uniquely determine each entity.
■ A candidate key of an entity set is a minimal super key ● ID is candidate key of instructor
● course_id is candidate key of course
■ Although several candidate keys may exist, one of the candidate keys is selected to be the primary key.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.18 ©Silberschatz, Korth and Sudarshan

Weak Entity Sets
■ Anentitysetthatdoesnothaveaprimarykeyisreferredtoasa weak entity set.
■ The existence of a weak entity set depends on the existence of a identifying entity set
● It must relate to the identifying entity set via a total, one-to- many relationship set from the identifying to the weak entity set
● Identifying relationship depicted using a double diamond
■ The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set.
■ The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.19 ©Silberschatz, Korth and Sudarshan

Keys for Relationship Sets
■ The combination of primary keys of the participating entity sets forms a super key of a relationship set.
● (s_id, i_id) is the super key of advisor
● NOTE: this means a pair of entity sets can have at most
one relationship in a particular relationship set.
! Example: if we wish to track multiple meeting dates between a student and her advisor, we cannot assume a relationship for each meeting. We can use a multivalued attribute though
■ Must consider the mapping cardinality of the relationship set when deciding what are the candidate keys
■ Need to consider semantics of relationship set in selecting the primary key in case of more than one candidate key
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.20 ©Silberschatz, Korth and Sudarshan

E-R Diagrams
student
ID
name tot_cred
instructor
ID
name salary
advisor
■ Rectangles represent entity sets.
■ Diamonds represent relationship sets.
■ Attributes listed inside entity rectangle
■ Underline indicates primary key attributes
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.21 ©Silberschatz, Korth and Sudarshan

Entity With Composite, Multivalued, and Derived Attributes
instructor
ID
name first_name
middle_initial
last_name address
street street_number street_name apt_number
city state zip
{ phone_number } date_of_birth
age ( )
Relationship Sets with Attributes
date
advisor
instructor
ID
name salary
student
ID
name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.22
©Silberschatz, Korth and Sudarshan

Alternative Notation: E-R Diagrams
■ Used in previous edition of the book ■ Same thing otherwise
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.23 ©Silberschatz, Korth and Sudarshan

Roles
■ Entity sets of a relationship need not be distinct
● Each occurrence of an entity set plays a “role” in the relationship
■ Thelabels“course_id”and“prereq_id”arecalledroles.
course_id prereq_id
course
course_id
title credits
prereq
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.24
©Silberschatz, Korth and Sudarshan

Cardinality Constraints
■ We express cardinality constraints by drawing either a directed line (→), signifying “one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.
■ one-to-one relationship between an instructor and a student
● an instructor is associated with at most one student via advisor
● and a student is associated with at most one instructor via advisor
advisor
(a)
7.25 ©Silberschatz, Korth and Sudarshan
instructor
ID
name salary
student
ID name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
instructor
student

One-to-Many Relationship
instructor student
■ one-to-many relationship between an instructor and a student ID advisor ID
name
name
● an instructor is associated with several (including 0) students salavriayadvisor tot_cred
● a student is associated with at most one instructor via advisor, (a)
advisor
(b)
7.26 ©Silberschatz, Korth and Sudarshan
instructor
ID name salary
student
ID
name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
instructor
student

(a)
Many-to-One Relationships
instructor ID
advisor
■ Inamany-to-onerelationshipbetweenaninstructorandamaestudent,
● and a student is associated with several (including 0) instructors
name
● asnalinasrtyructor is associated with at most one student via advisor,
via advisor
(b)
advisor
(c)
7.27 ©Silberschatz, Korth and Sudarshan
student ID
tot_cred
instructor
ID name salary
student
ID
name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020

Many-to-Many Relationship
■ Aninstructorisassociatedwithseveral(possibly0)studentsvia advisor
■ Astudentisassociatedwithseveral(possibly0)instructorsvia advisor
student
ID
name tot_cred
instructor
ID
name salary
advisor
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.28 ©Silberschatz, Korth and Sudarshan

Participation of an Entity Set in a Relationship Set
■ Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set
● E.g., participation of section in sec_course is total ! every section must have an associated course
■ Note: double box means weak entity – more about that later
■ Partial participation: some entities may not participate in any
relationship in the relationship set
● Example: participation of instructor in advisor is partial
course
course_id
title credits
section
sec_id semester year
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
sec_course
7.29 ©Silberschatz, Korth and Sudarshan

Alternative Notation for Cardinality Limits
■ Cardinality limits can also express participation constraints
0 ..* advisor 1..1
instructor
ID
name salary
student
ID name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.30
©Silberschatz, Korth and Sudarshan

E-R Diagram with a Ternary Relationship
project

student
ID
name tot_cred
instructor
ID
name salary
proj_ guide
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.31 ©Silberschatz, Korth and Sudarshan

Cardinality Constraints on Ternary Relationship
■ We allow at most one arrow out of a ternary (or greater degree) relationship to indicate a cardinality constraint
■ E.g., an arrow from proj_guide to instructor indicates each student has at most one guide for a project
■ If there is more than one arrow, there are two ways of defining the meaning.
● E.g., a ternary relationship R between A, B and C with arrows to B and C could mean
1. each A entity is associated with a unique entity from B and C or
2. each pair of entities from (A, B) is associated with a unique C entity, and each pair (A, C) is associated with a unique B
● Each alternative has been used in different formalisms
● To avoid confusion we outlaw more than one arrow
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.32 ©Silberschatz, Korth and Sudarshan

E-R Diagram with a Ternary Relationship
project

student
ID
name tot_cred
instructor
ID
name salary
proj_ guide
■ What does this mean?
● A student can have only one project, and only one instructor?
● For each student and project, there can be only one instructor, and for each student and instructor, there can be only one project?
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.33 ©Silberschatz, Korth and Sudarshan

E-R Diagram with a Ternary Relationship
project

student
ID
name tot_cred
instructor
ID
name salary
proj_ guide
■ What does this mean?
● A student can have only one project, and only one instructor?
● For each student and project, there can be only one instructor, and for each student and instructor, there can be only one project?
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.34 ©Silberschatz, Korth and Sudarshan

Weak Entity Sets (Cont.)
■ We underline the discriminator of a weak entity set with a dashed line.
■ We put the identifying relationship of a weak entity in a double diamond.
■ Primary key for section – (course_id, sec_id, semester, year)
sec_course
■ Note: the primary key of the strong entity set is not explicitly stored with the weak entity set, since it is implicit in the identifying relationship.
■ If course_id were explicitly stored, section could be made a strong entity, but then the relationship between section and course would be duplicated by an implicit relationship defined by the attribute course_id common to course and section
course
course_id
title credits
section
sec_id semester year
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.35 ©Silberschatz, Korth and Sudarshan

E-R Diagram for a University Enterprise
department
dept_name building budget
course_dept
inst_dept
stud_dept
student
ID name tot_cred
instructor
ID name salary
advisor
teaches
sec_course
takes
sec_time_slot
grade
section
sec_id semester year
course
course_id title credits
time_slot
time_slot_id
{ day start_time
end_time
}
course_id
prereq
prereq_id
sec_class
7.36
classroom
building
room_number
capacity
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
©Silberschatz, Korth and Sudarshan

Reduction to Relation Schemas
■ Entity sets and relationship sets can be expressed uniformly as relation schemas that represent the contents of the database.
■ AdatabasewhichconformstoanE-Rdiagramcanberepresented by a collection of schemas.
■ For each entity set and relationship set there is a unique schema that is assigned the name of the corresponding entity set or relationship set.
■ Each schema has a number of columns (generally corresponding to attributes), which have unique names.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.37 ©Silberschatz, Korth and Sudarshan

Representing Entity Sets With Simple Attributes
■ Astrongentitysetreducestoaschemawiththesameattributes
 student(ID, name, tot_cred)
■ Aweakentitysetbecomesatablethatincludesacolumnforthe primary key of the identifying strong entity set 

section ( course_id, sec_id, sem, year )
course
course_id
title credits
section
sec_id semester year
sec_course
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.38 ©Silberschatz, Korth and Sudarshan

Representing Relationship Sets
■ A many-to-many relationship set is represented as a schema with attributes for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set.
■ Example: schema for relationship set advisor advisor = (s_id, i_id)
advisor
student
ID
name tot_cred
instructor
ID
name salary
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.39 ©Silberschatz, Korth and Sudarshan

Composite and Multivalued Attributes
■ Composite attributes are flattened out by creating a separate attribute for each component attribute
● Example:givenentitysetinstructorwith composite attribute name with component attributes first_name and last_name the schema corresponding to the entity set has two attributes name_first_name and name_last_name
! Prefix omitted if there is no ambiguity
■ Ignoring multivalued attributes, extended instructor
schema is
instructor
ID
name first_name
middle_initial
last_name address
street street_number street_name apt_number
city state zip
{ phone_number } date_of_birth
age ( )
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
● instructor(ID,

first_name, middle_initial, last_name,
 street_number, street_name, 

apt_number, city, state, zip_code, 
 date_of_birth)
7.40 ©Silberschatz, Korth and Sudarshan

Composite and Multivalued Attributes
■ AmultivaluedattributeMofanentityEisrepresentedbyaseparate schema EM
● Schema EM has attributes corresponding to the primary key of E and an attribute corresponding to multivalued attribute M
● Example: Multivalued attribute phone_number of instructor is represented by a schema:

inst_phone= ( ID, phone_number)
● Each value of the multivalued attribute maps to a separate tuple of the relation on schema EM
! For example, an instructor entity with primary key 22222 and phone numbers 456-7890 and 123-4567 maps to two tuples:
(22222, 456-7890) and (22222, 123-4567)

Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.41 ©Silberschatz, Korth and Sudarshan

hes
urse
student
ID Multivalued Attribnaumtees (Cont.)
tot_cred
■ Special case:entity time_slot has only one attribute other than the primary-key attribute, and that attribute is multivalued
● Optimization: Don’t create the relation corresponding to the entity, just create the one corresponding to the multivalugerdadaettribute
advisor
takes
● time_slot(time_slot_id, day, start_time, end_time)
● Caveat: time_slot attribute of section (from sec_time_slot) cannot be
a foreign key due to this optimization
sec_time_slot
section
sec_id semester year
time_slot
time_slot_id
{ day start_time
end_time
}
Database System Concepts – 6th Edition sec_class
7.42 ©Silberschatz, Korth and Sudarshan
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
c
o

■ Use of entity sets vs. attributes
 


 
 

inst_ phone
Design Issues
instructor
ID
name
salary phone_number
phone
phone_number
location
instructor
ID
name salary
(a) (b)
■ Use of phone as an entity allows extra information about phone numbers (plus multiple phone numbers)
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.43 ©Silberschatz, Korth and Sudarshan

Design Issues
■ Use of entity sets vs. relationship sets

Possible guideline is to designate a relationship set to describe an action that occurs between entities
Unless that action can happen multiple times between same entities!
section_reg student_reg
registration
… … …
section
sec_id semester year
student
ID
name tot_cred
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.44 ©Silberschatz, Korth and Sudarshan

Design Issues
■ Binary versus n-ary relationship sets

Although it is possible to replace any nonbinary (n-ary, for n > 2) relationship set by a number of distinct binary relationship sets, a n- ary relationship set shows more clearly that several entities participate in a single relationship.
■ Placement of relationship attributes
e.g., attribute date as attribute of advisor or as attribute of student
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.45 ©Silberschatz, Korth and Sudarshan

Binary Vs. Non-Binary Relationships
■ Some relationships that appear to be non-binary may be better represented using binary relationships
● E.g., A ternary relationship parents, relating a child to his/her father and mother, is best replaced by two binary relationships, father and mother
! Using two binary relationships allows partial information (e.g., only mother being know)
● But there are some relationships that are naturally non-binary ! Example: proj_guide
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.46 ©Silberschatz, Korth and Sudarshan

Converting Non-Binary Relationships to Binary Form
■ In general, any non-binary relationship can be represented using binary relationships by creating an artificial entity set.
● ReplaceRbetweenentitysetsA,BandCbyanentitysetE,and three relationship sets:
1. RA, relating E and A 2. RB, relating E and B 
 3. RC, relating E and C
● CreateaspecialidentifyingattributeforE
● AddanyattributesofRtoE
● For each relationship (ai , bi , ci) in R, create
1.anewentityei intheentitysetE 2.add(ei ,ai)toRA 3.add(ei ,bi )toRB 4.add(ei ,ci)toRC
A A RA
B R C B RB E RC C
th (a) Database System Concepts – 6 Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
(b)
7.47
©Silberschatz, Korth and Sudarshan

Converting Non-Binary Relationships (Cont.)
■ Alsoneedtotranslateconstraints
● Translating all constraints may not be possible
● There may be instances in the translated schema that
 cannot correspond to any instance of R
! Exercise: add constraints to the relationships RA, RB and RC to ensure that a newly created entity corresponds to exactly one entity in each of entity sets A, B and C
● We can avoid creating an identifying attribute by making E a weak entity set (described shortly) identified by the three relationship sets
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.48 ©Silberschatz, Korth and Sudarshan

Extended E-R Features: Specialization
■ Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set.
■ These subgroupings become lower-level entity sets that have attributes or participate in relationships that do not apply to the higher-level entity set.
■ Depicted by a triangle component labeled ISA (E.g., instructor “is a” person).
■ Attributeinheritance–alower-levelentitysetinheritsallthe attributes and relationship participation of the higher-level entity set to which it is linked.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.49 ©Silberschatz, Korth and Sudarshan

Specialization Example
■ Overlapping – employee and student
■ Disjoint – instructor and secretary
■ Total and partial
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.50 ©Silberschatz, Korth and Sudarshan

Representing Specialization via Schemas
■ Method 1:
● Form a schema for the higher-level entity
● Form a schema for each lower-level entity set, include primary key of higher-level entity set and local attributes


schema
person student employee
attributes

ID, name, street, city 
 ID, tot_cred

ID, salary
● Drawback: getting information about, an employee requires accessing two relations, the one corresponding to the low-level schema and the one corresponding to the high-level schema
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.51 ©Silberschatz, Korth and Sudarshan

Representing Specialization as Schemas (Cont.)
■ Method 2:
● Form a schema for each entity set with all local and inherited attributes

schema
person
student employee
attributes

ID, name, street, city 

ID, name, street, city, tot_cred
 ID, name, street, city, salary
● If specialization is total, the schema for the generalized entity set (person) not required to store information
! Can be defined as a “view” relation containing union of specialization relations
! But explicit schema may still be needed for foreign key constraints
● Drawback: name, street and city may be stored redundantly for people who are both students and employees
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.52 ©Silberschatz, Korth and Sudarshan

Generalization
■ A bottom-up design process – combine a number of entity sets that share the same features into a higher-level entity set.
■ Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way.
■ The terms specialization and generalization are used interchangeably.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.53 ©Silberschatz, Korth and Sudarshan

Design Constraints on a Specialization/Generalization
■ Completeness constraint — specifies whether or not an entity in the higher-level entity set must belong to at least one of the lower- level entity sets within a generalization.
● total:anentitymustbelongtooneofthelower-levelentity sets
● partial:anentityneednotbelongtooneofthelower-level entity sets
■ Partial generalization is the default. We can specify total generalization in an ER diagram by adding the keyword total in the diagram and drawing a dashed line from the keyword to the corresponding hollow arrow-head to which it applies (for a total generalization), or to the set of hollow arrow- heads to which it applies (for an overlapping generalization).
■ The student generalization is total: All student entities must be either graduate or undergraduate. Because the higher-level entity set arrived at through generalization is generally composed of only those entities in the lower-level entity sets, the completeness constraint for a generalized higher-level entity set is usually total
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.54 ©Silberschatz, Korth and Sudarshan

Aggregation
■ Consider the ternary relationship proj_guide, which we saw earlier ■ Suppose we want to record evaluations of a student by a guide on a
project
project
instructor
student
proj_ guide
eval_ for
evaluation
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.55 ©Silberschatz, Korth and Sudarshan

Aggregation (Cont.)
■ Relationship sets eval_for and proj_guide represent overlapping information
● Every eval_for relationship corresponds to a proj_guide relationship
● However, some proj_guide relationships may not correspond to any eval_for relationships
! So we can’t discard the proj_guide relationship ■ Eliminate this redundancy via aggregation
● Treat relationship as an abstract entity
● Allows relationships between relationships ● Abstraction of relationship into new entity
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.56 ©Silberschatz, Korth and Sudarshan

Aggregation (Cont.)
■ Without introducing redundancy, the following diagram represents:
● A student is guided by a particular instructor on a particular project
● A student, instructor, project combination may have an associated evaluation
project
instructor
student
proj_ guide
eval_ for
evaluation
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.57 ©Silberschatz, Korth and Sudarshan

E-R Design Decisions
■ The use of an attribute or entity set to represent an object.
■ Whether a real-world concept is best expressed by an entity set or
a relationship set.
■ The use of a ternary relationship versus a pair of binary relationships.
■ The use of a strong or weak entity set.
■ The use of specialization/generalization – contributes to modularity
in the design.
■ The use of aggregation – can treat the aggregate entity set as a single unit without concern for the details of its internal structure.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.58 ©Silberschatz, Korth and Sudarshan

Summary of Symbols Used in E-R Notation
E
A1 A2
A2.1
A2.2 {A3}
A4()
E
R
R
RE R
entity set
relationship set
identifying relationship set for weak entity set
total participation of entity set in relationship
many-to-many R relationship
7.59
a􏰀ributes:
simple (A1), composite (A2) and multivalued (A3) derived (A4)
primary key
discriminating a􏰀ribute of weak entity set
many-to-one relationship
E
A1
E
A1
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
©Silberschatz, Korth and Sudarshan
R
one-to-one
R
l..h
E
cardinality

for weak entity set
A1
primary key
Symbols
total participation E discriminating Used in E-R Notation (Cont.)
R E R
of entity set in relationship
A1 a􏰀ribute of weak entity set
R
role-
R name E
E1
total
E3
many-to-many relationship
one-to-one relationship
role indicator
total (disjoint) generalization
R
R
l..h
E1
E
many-to-one relationship
cardinality limits
ISA: generalization or specialization
disjoint generalization
E2
E3
E1
E2
E2
E3
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.60
©Silberschatz, Korth and Sudarshan

many-to-many
relationship
E1*R*E2 E1 R E2
one-to-one E1 1 relationship
R 1 1
E2 E1 R E2
■ Chen, IDE1FX, … entity set E with
A2.1
A2.2
Alternative ER Notations
many-to-one
simple a􏰀ribute A1,
R
A3
A4
E1*R E2 E1
E2 E2
relationship
composite a􏰀ribute A2,
A1
A2
multivalued a􏰀ribute A3,
derived a􏰀ribute A4,
E
E1
and primary key A1
participation
in R: total (E1) E1 R and partial (E2)
E2
R
E1 total R E2
many-to-many
relationship
weak entity set
E1 * R * E2 generalization
ISA
generalization ISA
one-to-one E1 relationship
1
R 1 1
E2 E1 R E2
R
©Silberschatz, Korth and SuEda2rshan
Database System Concepts – 6th Edition many-to-one
*
R 7.61 E1 E2
Modified by T. Suel for CS6083, NYU Tandon, SEp1ring 2020
relationship

entity set E with
A2.1 A2.2
many-to-many relationship
one-to-one relationship
many-to-one relationship
E1 * R * E2
E2
Alternative ER Notations
simple a􏰀ribute A1,
composite a􏰀ribute A2, A1 multivalued a􏰀ribute A3,
derived a􏰀ribute A4,
and primary key A1
A2
A3
Chen
E A4
R
IDE1FX (Crows feet notation)
E1 1 R 1 E1 * R 1
E1 R Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
E2 RE2
E2
E2
R E2
participation
in R: total (E1) and partial (E2)
E1
R
E2
Database System Concepts – 6th Edition
total
7.62
©Silberschatz, Korth and Sudarshan
E1
E1
E1
weak entity set
generalization
ISA generalization ISA

UML
■ UML: Unified Modeling Language
■ UML has many components to graphically model different aspects
of an entire software system
■ UML Class Diagrams correspond to E-R Diagram, but several differences.
Database System Concepts – 6th Edition
Modified by T. Suel for CS6083, NYU Tandon, Spring 2020
7.63 ©Silberschatz, Korth and Sudarshan