Chapter 5
Chapter 5
INTERNATIONAL EDITION
Chapter 5
Entity Relationship (ER) Modelling
1
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
2
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Announcements
3
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
ER Model
• Attribute – characteristics of entities
– E.g. student – STU_LNAME, STU_FNAME, STU_E-
MAIL
– Required attributes – cannot be left empty
5
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Entities
• In UML notation, an entity is represented by a box
that is subdivided into three parts:
– Top: Entity name, a noun, is usually written in capital letters
– Middle part: for attributes
– Bottom part: for methods
6
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Keys
7
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Relational schema
Coronel & Crockett 9781844807321)
CAR
8
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Relational schema
Coronel & Crockett 9781844807321)
Student
9
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Primary Keys
• PKs are underlined in the ERD
• PK attributes are also underlined in the
relational schema
– A relational schema is a textual representation of the
database tables, where each table is described by its
name followed by the list of its attributes in
parentheses
– For example, a CAR entity may be represented by:
CAR (CAR_REG, MOD_CODE, CAR_YEAR,
CAR_COLOUR)
10
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
11
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
12
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Exercise on ER modeling
• Draw an entity-relationship diagram showing the following:
– A BOOK entity with the attributes of ISBN, book title, and data
published. Choose a PK.
– A RECIPE entity with the attributes of a recipe number, recipe name,
cooking time and oven setting
– The business rule describing the relationship between them is that a
book contains one or many recipes, but each recipe only appears in one
book.
– There is also an INGREDIENT table with the attributes of ingredient
number and ingredient name.
– Business rule: A recipe can have many ingredients and a particular
ingredient can be found in many recipes. How will RECIPE and
INGREDIENT be related?
13
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
14
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
A Recipe ERD
1…*
1…*
15
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Attributes
16
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
17
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
18
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
19
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Derived Attributes
• Attribute whose value may be calculated (derived) from other
attributes
• Need not be physically stored within database
• Can be derived by using an algorithm
– An 'algorithm' is an effective method for solving a problem expressed as a
finite sequence of instructions. Algorithms are used for calculation, data
processing, and many other fields (Wikipedia, 28 Jul 2010).
• Depicted with a ‘/’ before the attribute name
20
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
21
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Derived Attributes –
to store or not to store?
22
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Relationships
23
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Relationships
• Association between entities
• Entities in a relationship are also know as participants
• Relationships between entities always operate in both
directions
– A CUSTOMER may generate many INVOICEs
– Each INVOICE is generated by one CUSTOMER
– Each relationship can be classified as 1:*
– But might be part of a *:* relationship
Ternary Relationship
Entity2
30
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
32
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Multiplicity example
Multiplicity?
Participation?
Cardinality?
33
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Multiplicity example
36
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Existence Dependence
• Existence dependence
– Entity exists in database only when it is associated with
another related entity occurrence
– E.g. it has a mandatory foreign key – it can’t be null
37
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Weak Entities
• A weak entity meets two conditions
– Existence-dependent
• Cannot exist without entity with which it has a relationship
– Strong relationship
• Has a primary key that is partially or totally derived from parent
entity in relationship
– Example: DEPENDENT is existence-dependent on EMPLOYEE
and in a strong relationship meaning {PK} in DEPENDENT
table may be EMP_NUMBER (ie it is also the {FK})
38
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Summary
• Weak entity
– If FK is part of the PK
– Existence Dependent
– Strong relationship
• Strong entity
– If FK is not part of the PK
– Existence Independent
– Weak relationship
39
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
40
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
B. Developing an ER Diagram
41
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
42
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
43
Developing an ER Diagram - example 2
DATABASE SYSTEMS: Design Implementation and Management (Rob,
Coronel & Crockett 9781844807321)
• Tiny University
1. Tiny University is divided into several schools
2. Each school is administered by a dean, who is a lecturer
and has a grade of professor
3. Each school is composed of several departments
4. Each department may offer several courses
5. Each department may have many lecturers assigned to it
6. Each lecturer may teach up to four classes; each class is a
section of a course
7. Students may enroll in several classes, but students take
each class only once during any semester
8. Each department has many students
9. Each student has only a single major and is associated with
a single department 44
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
45
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
47
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
49
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
51
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
53
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
55
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
57
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
59
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
61
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
63
Developing an ER Diagram – Completed2
DATABASE SYSTEMS: Design Implementation and Management (Rob,
diagram
Coronel & Crockett 9781844807321)
64
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
65
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Design standards
• Guide in developing logical structures that
minimize data redundancies
• Minimize chance of anomalies occurring
• Avoiding nulls
• Govern the presentation of all components within
the database design
• Needed to formulate a proper design process,
evaluate existing design and trace the widely local
impact of changes in design
66
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Processing speeds
67
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Information requirements
68
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Summary
69
DATABASE SYSTEMS: Design Implementation and Management (Rob, 2
Coronel & Crockett 9781844807321)
Summary – 2
70