er model - outline
TRANSCRIPT
-
8/13/2019 ER Model - Outline
1/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
The Entity Relationship ModelOutline
Basis of an Entity-Relationship Diagram (ERD)
Entities, relationships and attributes
Multiplicity and participation constraints on
relationships
Keys, superkeys and primary keys
Cyclic relationships
Weak entity types
ISA relationships (specialisation/generalisation) An informal algorithm for constructing an ERD
http://find/ -
8/13/2019 ER Model - Outline
2/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
The Entity Relationship Model
An example of a high-level database model
Useful for design before moving to a lower level
model (e.g. relational) Alternatives include
UML (Unified Modelling Language) and ODL (Object Description Language)
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
3/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
The Components of the ER Model
Data structures entity types attributes relationship types
http://find/ -
8/13/2019 ER Model - Outline
4/38
DatabaseManagement
Peter Wood
Overview
EntitiesAttributes
Relationships
Weak Entity Types
ISA relationships
The Components of the ER Model
Data structures entity types attributes relationship types
Integrity constraints primary keys for entity types and relationship types,
and multiplicity (cardinality) constraints for relationship
types
http://find/ -
8/13/2019 ER Model - Outline
5/38
DatabaseManagement
Peter Wood
Overview
EntitiesAttributes
Relationships
Weak Entity Types
ISA relationships
The Components of the ER Model
Data structures entity types attributes relationship types
Integrity constraints primary keys for entity types and relationship types,
and multiplicity (cardinality) constraints for relationship
types
The ER model is only a partial data model, since ithas no standard manipulative part
http://find/http://goback/ -
8/13/2019 ER Model - Outline
6/38
DatabaseManagement
Peter Wood
Overview
EntitiesAttributes
Relationships
Weak Entity Types
ISA relationships
The Main Advantages of ERDs
The diagrams (ERDs) associated with entity-relationship
models
are relatively simple
are user-friendly
can provide a unified view of data, which is
independent of anyimplementeddata model
http://find/http://goback/ -
8/13/2019 ER Model - Outline
7/38
DatabaseManagement
Peter Wood
Overview
EntitiesAttributes
Relationships
Weak Entity Types
ISA relationships
The Building Blocks of an ERD
Entities and entity types (entity sets)
Relationships and relationship types Attributes, attribute values and domains
http://find/ -
8/13/2019 ER Model - Outline
8/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Entities and Entity Types
Anentityis a thing that exists and can be uniquelyidentified.
Anentity type(orentity set) is a collection of similar
entities.
An entity type
is similar to a class in object-oriented languages
has associatedattributes, which represent properties
of the entities comprising the entity type is represented in an ERD by a rectangle
http://find/ -
8/13/2019 ER Model - Outline
9/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Attributes
Attribute names(or simplyattributes) are properties of
entity types.
Each attribute usually has onlysimplevalues (e.g.
integers or character strings) represented by anovalin an ERD, with a line to the
rectangle representing its entity type
Sometimesmulti-valuedattributes (e.g. Phones) areallowed
represented by adouble ovalin an ERD
http://find/ -
8/13/2019 ER Model - Outline
10/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of Entity Type and Attributes
PersonNI#
Name Address
Phones
Each Person has a single Name, Address and
National Insurance number (NI#)
Each Person can have many Phones
http://find/ -
8/13/2019 ER Model - Outline
11/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Domain
Thedomainof an attribute of an entity type is the set of
constant values associated with that attribute.
Domains can be
atomicsuch as the domain of integers or the domain
of strings, or
set-valuedsuch as the domain of finite sets of
integers or of finite sets of strings.
http://find/ -
8/13/2019 ER Model - Outline
12/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Relationship Types
Arelationship typeis an association between two or more
entity types.
Relationship types are represented in an ERD by
diamond shapes,
with lines to each of the rectangles representing
entity types involved in the association
Example of a relationship typeTeachesbetween entity
typeLecturerand entity typeStudent:
Lecturer Teaches Student
http://find/ -
8/13/2019 ER Model - Outline
13/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
RelationshipsArelationshipis an instance of a relationship type, i.e., it
is the set of associations between theentitiescomprising
the entity types associated by the relationship type.
Above diagram isnotan ERD
Entities for one entity type on left (green)
Entities for another entity type on right (red)
Lines between entities show the relationship
http://find/ -
8/13/2019 ER Model - Outline
14/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Multiplicity Constraints in Relationship Types
many-to-one(or one-to-many)
An Employee Works in one Department or a
Department has many Employees.
one-to-oneA Manager Heads one Department and vice versa.
many-to-many
A Lecturer Teaches many Students and a Student is
Taught by many Lecturers.
D b
http://find/http://goback/ -
8/13/2019 ER Model - Outline
15/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of many-to-one relationship type
Employee Works-in Department
The arrowhead is drawn at the one end of the
relationship type
Each Employee Works-in one Department Each Department has many Employees working in it
D t bE l f l i hi
http://find/ -
8/13/2019 ER Model - Outline
16/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of many-to-one relationship
DatabaseE l f l i hi
http://find/ -
8/13/2019 ER Model - Outline
17/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of one-to-one relationship type
Manager Occupies Office
The arrowhead is drawn at both ends of the relationship
type
Each Manager Occupies one Office
Each Office has one Manager occupying it
DatabaseE l f t l ti hi
http://find/ -
8/13/2019 ER Model - Outline
18/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of one-to-one relationship
DatabaseE l f t l ti hi t
http://find/ -
8/13/2019 ER Model - Outline
19/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of many-to-many relationship type
Lecturer Teaches Student
No arrowheads are drawn
Each Lecturer Teaches many Students
Each Student is taught by many Lecturers
DatabaseE ample of man to man relationship
http://find/ -
8/13/2019 ER Model - Outline
20/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of many-to-many relationship
DatabaseMultiple relationship types
http://find/ -
8/13/2019 ER Model - Outline
21/38
DatabaseManagement
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Multiple relationship typesThere may be more than one relationship type between
two entity types.
Lecturer
Teaches
Tutors
Student
Teaches relationship type is many-to-many
Tutors relationship type is one-to-many (from
Lecturer to Student)
DatabaseParticipation Constraints in Relationships
http://find/ -
8/13/2019 ER Model - Outline
22/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Participation Constraints in Relationships
optionalrelationship e.g., an Employee may or may not be assigned to a
Department Participation of entity (e.g., Employee) in relationship
said to bepartial This is the default for relationships in our notation (Sometimes indicated by cardinality constraint of 0..*)
mandatoryrelationship e.g., every Course must be Taught by at least one
Lecturer Participation of entity (e.g., Course) in relationship
said to betotal Indicated by double lines in our notation (Sometimes indicated by cardinality constraint of 1..*)
DatabaseExample of Participation Constraints
http://find/ -
8/13/2019 ER Model - Outline
23/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of Participation Constraints
Lecturer Teaches Student
Some Lecturers may not Teach any Students Each Studentmustbe taught by at least one
Lecturer
Lecturer Teaches0..*
Student1..*
DatabaseBinary Versus General Relationships
http://find/ -
8/13/2019 ER Model - Outline
24/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Binary Versus General Relationships
Supplier PartSupplies
Project
each supplier may supply different parts to different
projects
Supplies is an example of a ternaryrelationship
DatabaseMKeys and Superkeys
http://find/ -
8/13/2019 ER Model - Outline
25/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Keys and Superkeys
Definition of a superkey. A set of attributes of an entity
type is asuperkeyif for each entity, saye, over that type,
the set of attribute values of the attributes in the superkey
uniquelyidentifiese.
Definition of a key. Akeyfor an entity type is a superkey
which isminimal.
simplekeys are single attribute keys, such as Emp#
and NI#.
compositekeys are keys having more than one
attribute, such as {Dname, College} and {Pname,
Address}.
DatabaseM t
http://find/http://goback/ -
8/13/2019 ER Model - Outline
26/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Definition of primary key of an entity type. Aprimary
keyis a key that has been designated as such by the
database designer.
The primary key guarantees logical access to every
entity.
Attributes that are members of the primary key of an
entity type areunderlinedin an ERD.
PersonNI#
Name Address
Phones
DatabaseManagementCyclic Relationship Types
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
27/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Cyclic Relationship Types
Definition. Acyclic relationshiptype (also calledrecursive) is a relationship type between two occurrences
of the same entity type.
Examples:
Marriage between Person and itself. Parent-Child between Person and itself.
Part-Sub-Part between Part and itself.
With each entity type in a cyclic relationship type we
associate arole, represented by labels on lines in anERD.
DatabaseManagementExample of a Cyclic Relationship Type with
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
28/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Example of a Cyclic Relationship Type with
Roles
PersonNI#
Name Address
Phones
Married
husband wife
Roles are specified by husband and wife labels.
DatabaseManagementRelationship Types with Attributes
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
29/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Relationship Types with Attributes
Examples:
attribute Date associated with the relationship type
Married attribute Price associated with the relationship type
Supplies
Supplier PartSupplies
Price
Each Supplier Supplies a Part atacertainPrice.
DatabaseManagementWeak Entity Types
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
30/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Weak Entity Types
Definition. A Weak Entity Type is an entity type that does
not have sufficient attributes to form a primary key.
The existence of a weak entity depends on the
existence of anidentifyingorownerentity type.
The relationship between them is called an
identifying(ID) relationship. The weak entity type must have a discriminator(one
or more attributes) for distinguishing among its
entities.
For example, in an employees database, Childentitiesexistonly if their corresponding Parent
employee entity exists.
DatabaseManagementWeak Entity Type and ID Relationship
http://find/ -
8/13/2019 ER Model - Outline
31/38
Management
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Weak Entity Type and ID Relationship
Parent
Has
Child
NI#
Pname Address
Age
Cname Age
DatabaseManagementWeak Entity Types in an ERD
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
32/38
g
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
y yp
A weak entity type is identified by a double rectangle. The discriminator is underlined by a dashed line.
An identifying relationship is identified by a double
diamond.
The fact that the existence of the weak entityrequires the existence of an owner entity is captured
by the total participation of the weak entity type in the
relationship (double line).
Theprimary keyof a weak entity type is the
combination of the primary key of its owner type andits discriminator, e.g., (NI#, Cname) for Child.
DatabaseManagementISA Relationship Types
http://find/ -
8/13/2019 ER Model - Outline
33/38
g
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
p yp
When an entity type contains certain entities that
have special properties not shared by all entities, this
suggests two entity types should be created with an
ISA relationship type between them.
Also known as generalisation/specialisation.
E.g. An Employee ISA Person and a Student ISA
Person (seeISA relationship types)
If Employee ISA Person then Employee inheritsall
the attributes of Person.
DatabaseManagementISA Relationships
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
34/38
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
p
Person
Name Number
ISA
EmployeeSalary Student Degree
Attributes of Employee: Name, Number and Salary.
Attributes of Student: Name, Number and Degree.
DatabaseManagementInformal Algorithm for Constructing an ERD
http://goforward/http://find/http://goback/ -
8/13/2019 ER Model - Outline
35/38
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
g g
1. Identify the entity types (including weak entity types)
of the enterprise.
2. Draw some instances of the identified entity types.
3. Identify the relationships (including ISA and ID
relationships) of the enterprise.
4. Classify each relationship identified in step 3
according to its multiplicity, i.e. if it is a one-to-one,
many-to-one or many-to-many.5. Draw some instances of the identified relationships.
6. Draw an ERD with the entity types and the
relationships between them.
7. Identify the attributes of entity types and their
underlying domain
8. Identify a primary key for each entity type.
9. Draw some instances of attribute values of entities.
10. Add the attributes and keys to the ERD drawn in step
6.
DatabaseManagementERD Example
http://find/ -
8/13/2019 ER Model - Outline
36/38
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Employee
NameNumber
ISA
Mechanic SalesmanDoes
RepairJobNumber
Description
Cost
Repairs Car
License
ModelYear
Manufacturer
Buys
Price
Date
Sells
Date
Price
Commission
Client ID
Name Phone
Address
buyerseller
DatabaseManagementFor more information
http://find/ -
8/13/2019 ER Model - Outline
37/38
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationshipsSee, e.g.,
Chapter 12 of [CB10].
Chapter 7 of [SKS11].
Chapter 4 of [UW08].
DatabaseManagementT. Connolly and C. Begg.
D t b S t A P ti l A h t
http://find/ -
8/13/2019 ER Model - Outline
38/38
Peter Wood
Overview
Entities
Attributes
Relationships
Weak Entity Types
ISA relationships
Database Systems: A Practical Approach toDesign, Implementation, and Management.Addison-Wesley, fifth edition, 2010.
A. B. Silberschatz, H. F. Korth, andS. Sudarshan.Database System Concepts.McGraw-Hill, sixth edition, 2011.
J. D. Ullman and J. Widom.A First Course in Database Systems.Prentice Hall, third edition, 2008.
http://find/