0% found this document useful (0 votes)
30 views26 pages

L05-ER Model

EEE notes VII sem of DBMS

Uploaded by

Soham Lohiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views26 pages

L05-ER Model

EEE notes VII sem of DBMS

Uploaded by

Soham Lohiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

L05 - Entity-Relationship

(ER) model
Database Design Using the E-R Model
Design Phases
• Initial phase -- characterize fully the data needs of the
prospective database users.
• Second phase -- choosing a data model
• Applying the concepts of the chosen data model
• Translating these requirements into a conceptual schema
of the database.
• A fully developed conceptual schema indicates the
functional requirements of the enterprise.
• Describe the kinds of operations (or transactions) that will
be performed on the data.

16-Aug-22 Entity-Relationship (ER) model 2


Design Phases
▪ Final Phase -- Moving from an abstract data model to the
implementation of the database
• 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

16-Aug-22 Entity-Relationship (ER) model 3


Design Alternatives
▪ In designing a database schema, we must ensure that we avoid two
major pitfalls:
• Redundancy: a bad design may result in repeat information.
▪ Redundant representation of information may lead to data
inconsistency among the various copies of information

• Incompleteness: a bad design may make certain aspects of the


enterprise difficult or impossible to model.

▪ Avoiding bad designs is not enough. There may be a large number of


good designs from which we must choose.

16-Aug-22 Entity-Relationship (ER) model 4


Design Approaches
▪ Entity Relationship Model
• 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
• Formalize what designs are bad, and test for them
16-Aug-22 Entity-Relationship (ER) model 5
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 data model employs three basic concepts:
• entity sets,
• relationship sets,
• attributes.
• The ER model also has an associated diagrammatic
representation, the ER diagram, which can express the overall
logical structure of a database graphically.
16-Aug-22 Entity-Relationship (ER) model 6
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: set of all persons, 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, salary )
course= (course_id, title, credits)
• A subset of the attributes form a primary key of the entity set; i.e., uniquely
identifying each member of the set.

16-Aug-22 Entity-Relationship (ER) model 7


Entity Sets - instructor and student

16-Aug-22 Entity-Relationship (ER) model 8


Representing Entity sets in ER Diagram
▪ Entity sets can be represented graphically as
follows:
• Rectangles represent entity sets.
• Attributes listed inside entity rectangle
• Underline indicates primary key attributes

16-Aug-22 Entity-Relationship (ER) model 9


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
16-Aug-22 Entity-Relationship (ER) model 10
Relationship Sets
▪ Example: we define the relationship set advisor to denote the
associations between students and the instructors who act as their
advisors.
▪ Pictorially, we draw a line between related entities.

16-Aug-22 Entity-Relationship (ER) model 11


Representing Relationship Sets via ER Diagrams
• Diamonds represent relationship sets.

16-Aug-22 Entity-Relationship (ER) model 12


Relationship Sets with Attributes

16-Aug-22 Entity-Relationship (ER) model 13


Roles
• Entity sets of a relationship need not be distinct
• Each occurrence of an entity set plays a “role” in the relationship
• The labels “course_id” and “prereq_id” are called roles.

16-Aug-22 Entity-Relationship (ER) model 14


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
16-Aug-22 Entity-Relationship (ER) model 15
Non-binary Relationship Sets
• Most relationship sets are binary
• There are occasions when it is more convenient to represent
relationships as non-binary.
• E-R Diagram with a Ternary Relationship

16-Aug-22 Entity-Relationship (ER) model 16


Complex Attributes
• Attribute types:
• 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
• Domain – the set of permitted values for each attribute

16-Aug-22 Entity-Relationship (ER) model 17


Composite Attributes
Composite attributes allow us to divided attributes into subparts (other attributes).

composite name address


attributes

first_name middle_initial last_name street city state postal_code

component
attributes
street_number street_name apartment_number

16-Aug-22 Entity-Relationship (ER) model 18


Representing Complex Attributes in ER Diagram

16-Aug-22 Entity-Relationship (ER) model 19


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
16-Aug-22 Entity-Relationship (ER) model 20
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

16-Aug-22 Entity-Relationship (ER) model 21


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

16-Aug-22 Entity-Relationship (ER) model 22


Representing Cardinality Constraints in ER Diagram
• 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 :


• A student is associated with at most one instructor via the relationship advisor
• A student is associated with at most one department via stud_dept

16-Aug-22 Entity-Relationship (ER) model 23


One-to-Many Relationship
• one-to-many relationship between an instructor and a student
• an instructor is associated with several (including 0) students
via advisor
• a student is associated with at most one instructor via advisor

16-Aug-22 Entity-Relationship (ER) model 24


Many-to-One Relationships
• In a many-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 several (including 0) instructors via
advisor

16-Aug-22 Entity-Relationship (ER) model 25


Many-to-Many Relationship
• An instructor is associated with several (possibly 0) students via advisor
• A student is associated with several (possibly 0) instructors via advisor

16-Aug-22 Entity-Relationship (ER) model 26

You might also like