Data Modeling Using The Entity-Relationship (ER) Model

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 38

Data Modeling Using the

Entity-Relationship (ER) Model


Modeling
• A database can be modeled as:
– a collection of entities,
– relationship among entities.
• An entity is an object that exists and is
distinguishable from other objects.
– Example: specific person, company, event, plant

• Entities have attributes


– Example: people have names and addresses
• An entity set is a set of entities of the same type
that share the same properties.
– Example: set of all persons, companies, trees, holidays
ER Model Concepts
• Entities and Attributes
– Entities are specific objects or things in the mini-world that are
represented in the database. For example the EMPLOYEE John
Smith, the Research DEPARTMENT, the ProductX PROJECT
– Attributes are properties used to describe an entity. For example
an EMPLOYEE entity may have a Name, SSN, Address, Sex,
BirthDate
– A specific entity will have a value for each of its attributes. For
example a specific employee entity may have Name='John
Smith', SSN='123456789', Address ='731, Fondren, Houston,
TX', Sex='M', BirthDate='09-JAN-55‘
– Each attribute has a value set (or data type) associated with it –
e.g. integer, string, subrange, enumerated type, …
Types of Attributes (1)
• Simple
– Each entity has a single atomic value for the attribute. For
example, SSN or Sex.
• Composite
– The attribute may be composed of several components. For
example, Address (Apt#, House#, Street, City, State, ZipCode,
Country) or Name (FirstName, MiddleName, LastName).
Composition may form a hierarchy where some components are
themselves composite.
• Multi-valued
– An entity may have multiple values for that attribute. For
example, Color of a CAR or PreviousDegrees of a STUDENT.
Denoted as {Color} or {PreviousDegrees}.
Types of Attributes (2)
• In general, composite and multi-valued attributes may
be nested arbitrarily to any number of levels although
this is rare. For example, PreviousDegrees of a
STUDENT is a composite multi-valued attribute denoted
by {PreviousDegrees (College, Year, Degree, Field)}.
Entity Types and Key Attributes
• Entities with the same basic attributes are grouped or typed into an
entity type. For example, the EMPLOYEE entity type or the
PROJECT entity type.
• An attribute of an entity type for which each entity must have a
unique value is called a key attribute of the entity type. For example,
SSN of EMPLOYEE.
• A key attribute may be composite. For example, VehicleTagNumber
is a key of the CAR entity type with components (Number, State).
• An entity type may have more than one key. For example, the CAR
entity type may have two keys:
– VehicleIdentificationNumber (popularly called VIN) and
– VehicleTagNumber (Number, State), also known as license_plate number.
ENTITY SET
corresponding to the ENTITY TYPE CAR
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color

car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
.
.
.
Relationships and Relationship Types
• A relationship relates two or more distinct entities with a specific
meaning.
– For example, EMPLOYEE John Smith works on the ProductX PROJECT
or EMPLOYEE Franklin Wong manages the Research DEPARTMENT.

• Relationships of the same type are grouped or typed into a


relationship type.
– For example, the WORKS_ON relationship type in which EMPLOYEEs
and PROJECTs participate, or the MANAGES relationship type in which
EMPLOYEEs and DEPARTMENTs participate.

• The degree of a relationship type is the number of participating


entity types.
– Both MANAGES and WORKS_ON are binary relationships.
Relationship Sets
• An attribute can also be property of a relationship set.
• For instance, the depositor relationship set between entity
sets customer and account may have the attribute access-
date
Degree of a Relationship Set
• Refers to number of entity sets that participate in a
relationship set.
• Relationship sets that involve two entity sets are binary
(or degree two). Generally, most relationship sets in a
database system are binary.
• Relationship sets may involve more than two entity sets.
• Relationships between more than two entity sets are rare.
Most relationships are binary.
Example: Suppose employees of a bank may have jobs
(responsibilities) at multiple branches, with different jobs
at different branches. Then there is a ternary relationship
set between entity sets employee, job, and branch
Attributes
An entity is represented by a set of attributes, that is
descriptive properties possessed by all members of an entity
set. Example:
customer = (customer_id, customer_name, customer_street, city )
Domain – the set of permitted values for each attribute
• Attribute types:
– Simple and composite attributes.
– Single-valued and multi-valued attributes
• Example: multivalued attribute: phone_numbers
– Derived attributes
• Can be computed from other attributes
• Example: age, given date_of_birth
Composite Attributes
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
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
Mapping Cardinalities

Many to one Many to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
Keys
• A super key of an entity set is a set of one or more
attributes whose values uniquely determine each
entity.
• A candidate key of an entity set is a minimal super
key
– Customer_id is candidate key of customer
– account_number is candidate key of account
• Although several candidate keys may exist, one of
the candidate keys is selected to be the primary key.
Keys for Relationship Sets
• The combination of primary keys of the participating
entity sets forms a super key of a relationship set.
– (customer_id, account_number) is the super key of
depositor
• 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
E-R Diagrams

 Rectangles represent entity sets.


 Diamonds represent relationship sets.
 Lines link attributes to entity sets and entity sets to relationship sets.
 Ellipses represent attributes
 Double ellipses represent multivalued attributes.
 Dashed ellipses denote derived attributes.
 Underline indicates primary key attributes (will study later)
E-R Diagram With Composite, Multivalued, and Derived
Attributes
Relationship Sets with Attributes
Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles;
they specify how employee entities interact via the
works_for relationship set.
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 loan in borrower is total
 every loan must have a customer associated to it via borrower
 Partial participation: some entities may not participate in any
relationship in the relationship set
 Example: participation of customer in borrower is partial
Alternative Notation for Cardinality Limits
 Cardinality limits can also express participation
constraints
E-R Diagram with a Ternary Relationship
Weak Entity Sets
• An entity set that does not have a primary key is referred
to as a 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 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.
Weak Entity Sets
• We depict a weak entity set by double rectangles.
• We underline the discriminator of a weak entity set with a dashed line.
• payment_number – discriminator of the payment entity set
• Primary key for payment – (loan_number, payment_number)
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. customer “is a”
person).
• Attribute inheritance – a lower-level entity set inherits all the
attributes and relationship participation of the higher-level entity set
to which it is linked.
Specialization Example
Extended ER Features: 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.
Specialization and Generalization
• Can have multiple specializations of an entity set based
on different features.
• E.g. permanent_employee vs. temporary_employee, in
addition to officer vs. secretary vs. teller
• Each particular employee would be
– a member of one of permanent_employee or
temporary_employee,
– and also a member of one of officer, secretary, or teller
• The ISA relationship also referred to as superclass -
subclass relationship
Aggregation
 Consider the ternary relationship works_on, which we saw earlier

 Suppose we want to record managers for tasks performed by an


employee at a branch
Aggregation (Cont.)
• Relationship sets works_on and manages represent
overlapping information
– Every manages relationship corresponds to a works_on relationship.
– However, some works_on relationships may not correspond to any manages
relationships
– So we can’t discard the works_on relationship
• Eliminate this redundancy via aggregation
– Treat relationship as an abstract entity
– Allows relationships between relationships
– Abstraction of relationship into new entity
• Without introducing redundancy, the following diagram
represents:
– An employee works on a particular job at a particular branch
– An employee, branch, job combination may have an associated manager
E-R Diagram With Aggregation
E-R Diagram for a Banking Enterprise
Reduction to Relation Schemas
• Primary keys allow entity sets and relationship sets to
be expressed uniformly as relation schemas that
represent the contents of the database.
• A database which conforms to an E-R diagram can be
represented 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.
Representing Entity Sets as Schemas
• A strong entity set reduces to a schema with the
same attributes.
• A weak entity set becomes a table that includes a
column for the primary key of the identifying
strong entity set
payment =
( loan_number, payment_number, payment_date, payment_amount )
Representing Relationship Sets as Schemas
• 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 borrower
borrower = (customer_id, loan_number )
Some of the Currently Available Automated Database
COMPANY TOOL Design Tools FUNCTIONALITY
Embarcadero ER Studio Database Modeling in ER and IDEF1X
Technologies
DB Artisan Database administration and space and security
management
Oracle Developer 2000 and Database modeling, application development
Designer 2000
Popkin Software System Architect 2001 Data modeling, object modeling, process modeling,
structured analysis/design
Platinum Platinum Enterprice Data, process, and business component modeling
Technology Modeling Suite: Erwin,
BPWin, Paradigm Plus
Persistence Inc. Pwertier Mapping from O-O to relational model

Rational Rational Rose Modeling in UML and application generation in C++


and JAVA
Rogue Ware RW Metro Mapping from O-O to relational model

Resolution Ltd. Xcase Conceptual modeling up to code maintenance

Sybase Enterprise Application Suite Data modeling, business logic modeling


Visio Visio Enterprise Data modeling, design and reengineering Visual Basic
and Visual C++

You might also like