Chapter 3 Conceptual Database Design and E-R Modeling (2)
Chapter 3 Conceptual Database Design and E-R Modeling (2)
1
Topics (Continued)
Topics Subtopics
3. 3.1 Conceptual Database Design
Conceptual 3.1.1.Steps to Build Conceptual Data Model
Database Design 3.1.2.Symbols Used in ER Diagram
and E-R 3.2 Entity-Relationship Diagram Building Blocks
Modeling 3.2.1.Entity Type
3.2.2.Attributes
3.2.3.Relational (cardinality and Degree of
Relationship
3.2.4.Participation Constraints
3.3 Design ER Diagram
3.4 Mapping ER Diagram to Relational Tables
3.4.1. ER Diagram to Table Mapping Algorithms
3.4.2. Mapping Strong Entities to Tables
3.4.3. Mapping Weak Entity to Tables
3.4.4. Mapping Composite Attribute to Tables
3.4.5. Mapping Multivalued Attributes to Tables
2
Topics
Topics Subtopics
3. 3.5 Problem With ER Models
Conceptual 3.6 Enhanced Entity Relationship (EER) Models
Database Design 3.6.1. Superclass and Subclass
and E-R 3.6.2. Relationship between Superclass and
Modeling Subclass
3.6.3. Generalization and Specialization
3.6.4. Constraints on Specialization and
Generalization
3.6.5. Inheritance
3.6.6. Union
3.7 Design EER Diagram
3.8 Mapping EER Model to Relations
3
Conceptual Database Design
The process of constructing a model of the data used in an
relationship model.
4
Steps to Build Conceptual Data Model
Step 1.1 Identify entity types
5
Symbols Used in ER Diagram
6
Symbols Used in ER Diagram
7
Entity-Relationship Diagram Building
Blocks
The basic building blocks of Entity- Relationship
diagram are
Entity,
Attribute and
Relationship.
8
Entity-Relationship Diagram Building
Blocks
1. Entity
An entity can be a real-world object, either
animate or inanimate, that can be easily
identifiable. For example, in a school database,
students, teachers, classes, and courses offered
can be considered as entities.
9
Entity-Relationship Diagram Building
Blocks
Entity Type
The entity type is a collection of the entity having similar
attributes. In the above Student table example, we have each
row as an entity and they are having common attributes i.e each
row has its own value for attributes Roll_no, Age, Student_name
and Mobile_no. So, we can define the above STUDENT table as
an entity type because it is a collection of entities having the
same attributes.
So, an entity type in an ER diagram is defined by a
name(here, STUDENT) and a set of attributes(here, Roll_no,
Student_name, Age, Mobile_no). The table below shows how
the data of different entities( different students) are stored.
10
Entity-Relationship Diagram Building
Blocks
Entity Set
Entity Set is a collection of entities of the same entity type. In
the above example of STUDENT entity type, a collection of
entities from the Student entity type would form an entity set.
We can say that entity type is a superset of the entity set
as all the entities are included in the entity type.
Example 1: In the below example, two entities E1 (2, Angel, 19,
8709054568) and E2(4, Analisa, 21, 9847852156) form an
entity set.
11
Entity-Relationship Diagram Building
Blocks
Types of Entity type
o Strong Entity Type
o Weak Entity Type
Strong Entity Type: Strong entity are those entity types
which has a key attribute. The primary key helps in
identifying each entity uniquely. It is represented by a
rectangle. In the above example, Roll_no identifies each
element of the table uniquely and hence, we can say that
STUDENT is a strong entity type.
12
Entity-Relationship Diagram Building
Blocks
Weak Entity Type : Weak entity type doesn't have a key
attribute. Weak entity type can't be identified on its own.
It depends upon some other strong entity for its distinct
identity. This can be understood with a real-life example. There
can be children only if the parent exits. There can be no
independent existence of children. There can be a room only if
building exits. There can be no independent existence of a room.
A weak entity is represented by a double outlined rectangle. The
relationship between a weak entity type and strong entity type
is called an identifying relationship and shown with a double
outlined diamond instead of a single outlined diamond. This
representation can be seen in the diagram below.
13
Entity-Relationship Diagram Building
Blocks
Example: If we have two tables of
Customer(Customer_id, Name, Mobile_no, Age, Gender)
and Address(Locality, Town, State, Customer_id). Here we
cannot identify the address uniquely as there can be many
customers from the same locality. So, for this, we need an
attribute of Strong Entity Type i.e ‘Customer’ here to
uniquely identify entities of 'Address' Entity Type.
14
Entity-Relationship Diagram Building
Blocks
2. Attributes
Entities are represented by means of their
properties, called attributes. All attributes have
values. For example, a student entity may have name,
class, and age as attributes.
There exists a domain or range of values that can be
assigned to attributes. For example, a student's name
cannot be a numeric value. It has to be alphabetic. A
student's age cannot be negative, etc.
15
Entity-Relationship Diagram Building
Blocks
Types of Attributes
• Simple attribute − Simple attributes are atomic
values, which cannot be divided further. For example,
a student's phone number is an atomic value of 10
digits.
• Composite attribute − Composite attributes are made
of more than one simple attribute. For example, a
student's complete name may have first_name and
last_name.
16
Entity-Relationship Diagram Building
Blocks
• Derived attribute − Derived attributes are the attributes that
do not exist in the physical database, but their values are
derived from other attributes present in the database. For
example, average_salary in a department should not be saved
directly in the database, instead it can be derived. For another
example, age can be derived from data_of_birth.
• Single-value attribute − Single-value attributes contain single
value. For example − Social_Security_Number.
• Multi-value attribute − Multi-value attributes may contain more
than one values. For example, a person can have more than one
phone number, email_address, etc.
17
Entity-Relationship Diagram Building
Blocks
3. Relationship
The association among entities is called a relationship. For
example, an employee works_at a department, a student
enrolls in a course. Here, Works_at and Enrolls are called
relationships.
Relationship Set
A set of relationships of similar type is called a
relationship set. Like entities, a relationship too can have
attributes. These attributes are called descriptive
attributes.
18
Relational (cardinality and Degree of
Relationship)
Degree of Relationship
Ternary = degree 3
n-ary = degree
19
Degree of a Relationship
20
Relationships, Associations, and Constraints
Mapping Cardinalities
21
Relationships, Associations, and Constraints
22
Relationships, Associations, and Constraints
23
Design ER diagrams
▪ We can express the overall logical structure of a database
graphically with an E-R diagram.
▪ Entity-Relationship Diagram (ERD) is a graphical representation of a
Entity-Relationship Model.
▪ ERDs are made from Entities, Attributes, and Relations.
Its components are:
•rectangles representing entity sets.
•ellipses representing attributes.
•diamonds representing relationship sets.
•lines linking attributes to entity sets and entity sets to
relationship sets.
S.S.N Street Note that this is a poor example of a entity, since the name is
name City
represented as one attribute and there is no street number
attribute.
We will consider the problem of designing good entities later,
here we are just concerned with explaining their graphical
representation.
Students Also note that one of the attributes is underlined, we will explain
why later.
24
Design ER diagrams Continued
We can express the overall logical structure of a database graphically
with an E-R diagram. The “since” attribute in this example is called a
descriptive attribute, since it describes the
Its components are: mapping from A to B
Concise.
26
University Entity-Relationship Diagram
Entity
27
Attributes
(Naming Guidelines)
An attribute name:
Should be a noun and capitalize the first letter of each word.
(Example: Student_ID.)
Should be unique.
Should follow a standard format. (Example: Student_GPA, not
GPA_of_Student.)
30
Exercise
32
Exercise - ERD
ER diagram for the company Database
33
Mapping ER-models to relational Database
Schema
34
ER Diagram -to-Relational Mapping
Algorithm
Mapping of Regular Entity Types.
For each regular (strong) entity type E in the ER
schema, create a relation R that includes all the simple
attributes of E.
Choose one of the key attributes of E as the primary
key for R.
If the chosen key of E is composite, the set of simple
attributes that form it will together form the primary
key of R.
Example: We create the relations
EMPLOYEE,DEPARTMENT, and PROJECT in the
relational schema corresponding to the regular
entities in the ER diagram.
35
ER Diagram -to-Relational Mapping
Algorithm
SSN, DNUMBER, and PNUMBER are the primary keys for
the relations EMPLOYEE, DEPARTMENT, and PROJECT.
Mapping of Weak Entity Types
For each weak entity type W in the ER schema with owner
entity type E, create a relation R & include all simple
attributes (or simple components of composite attributes)
of W as attributes of R.
Also, include as foreign key attributes of R the primary key
attribute(s) of the relation(s) that correspond to the owner
entity type(s).
The primary key of R is the combination of the primary
key(s) of the owner(s) and the partial key of the weak
entity type W, if any.
36
ER Diagram -to-Relational Mapping
Algorithm
Example: Create the relation DEPENDENT in this step
to correspond to the weak entity type DEPENDENT.
38
ER Diagram -to-Relational Mapping
Algorithm
Mapping of Composite Attribute to Tables.
39
ER Diagram -to-Relational Mapping
Algorithm
Mapping of Composite Attribute to Tables.
40
ER Diagram -to-Relational Mapping
Algorithm
Mapping of Multivalued Attribute to Tables.
Multi valued attribute are those which can take many values.
Fore example: Mobile_Number, Hobbies, Skills etc..
For each multivalued attribute A, create a new relation R.
This relation R will include an attribute corresponding to A, plus
the primary key attribute K-as a foreign key in R-of the relation
that represents the entity type of relationship type that has A as
an attribute.
The primary key of R is the combination of A and K. If the
multivalued attribute is composite, we include its simple
components.
41
ER Diagram -to-Relational Mapping
Algorithm
Example: The relation DEPT_LOCATIONS is
created.
The attribute DLOCATION represents the multivalued
attribute LOCATIONS of DEPARTMENT, while DNUMBER-
as foreign key-represents the primary key of the
DEPARTMENT relation.
42
Problems with ER models
Problems may arise when designing an ER model called
connection traps.
Two main types of connection traps are called fan traps and
chasm traps.
43
Problems with ER models
1. Fan trap
A fan trap my exist where two or more 1:* relationships fan out
(spread out) from the same entity.
This means that certain entity occurrences that are related can
only be connected using a pathway that can be ambiguous.
44
Example of a fan trap
45
Example of a fan trap
47
Restructured ER Model with Fan Trap Removed
48
Problems with ER models
2. Chasm trap
49 ©Pearson Education
2009
An Example of a Chasm Trap
50
An Example of a Chasm Trap
51
ER Model restructured to remove Chasm Trap
52
Restructured ER Model with Chasm Trap Removed
53
The Enhanced Entity-Relationship (EER)
Model
Enhanced ER (EER) model
Supertype/subtype
Class/subclass relationship
Type inheritance
Subclass entity inherits all attributes and relationships of
superclass
Specialization and Generalization
Specialization
Process of defining a set of subclasses of an entity type
Generalization
Attribute-defined specialization
User-defined
Constraints on Specialization and Generalization
(cont.)
Disjointness constraint
Specifies that the subclasses of the specialization must be
disjoint
Specialization hierarchy
Specialization lattice
Multiple inheritance
Single inheritance
Specialization process
UNIVERSITY database
relationships
Subclass
Specialization
Generalization
Predicate-defined
User-defined
Relationship type