0% found this document useful (0 votes)
19 views38 pages

Chapter 4

Uploaded by

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

Chapter 4

Uploaded by

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

Chapter 4

ERD (Entity Relationship


Modeling)
Entity Relationship Model

• Design Process
• Modeling
• Cardinality Constraints
• E-R Diagram
• Types of Entity Sets
• Design of the University Database
• Examples of ER Diagram
Design Phases
• The initial phase of database design is to
characterize fully the data needs of the prospective
database users.
• Next, the designer chooses a data model and, by
applying the concepts of the chosen data model,
translates these requirements into a conceptual
schema of the database.
• A fully developed conceptual schema also indicates
the functional requirements of the enterprise. In a
“specification of functional requirements”, users
describe the kinds of operations (or transactions)
that will be performed on the data.
Design Phases
The process of moving from an abstract data model to the
implementation of the database proceeds in two final design
phases.
• 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
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
ER model -- Database Modeling

• The ER data model was developed to facilitate


database design by allowing specification of an
enterprise schema that represents the overall logical
structure of a database.
• The ER model is very useful in mapping the meanings
and interactions of real-world enterprises onto a
conceptual schema. Because of this usefulness, many
database-design tools draw on concepts from the ER
model.
• The ER data model employs three basic concepts:
– entity sets,
– relationship sets,
– attributes.
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, street, city, salary )
course= (course_id, title, credits)
• A subset of the attributes form a primary key of the
entity set, uniquely identifiying each member of the set.
Entity Sets -- instructor and student

instructor_ID instructor_name student-ID student_name


Relationship Sets

• An attribute can also be associated with a relationship


set.
• For instance, relationship set between entity sets
instructor and student may have the attribute date
which tracks when the student started being associated
with the instructor:
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.
Example: students work on research projects
under the guidance of an instructor.
relationship proj_guide is a ternary relationship
between instructor, student, and project
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
Complex Attributes

• Attribute types:
– Simple and composite attributes.
– Single-valued and multi-valued attributes
• Example: multi-valued 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
Composite Attributes
Types of Entity
An entity set may be of the following two types-

• Strong entity set


• Weak entity set
Strong Entity Set
• A strong entity set is an entity set that contains sufficient
attributes to uniquely identify all its entities.
• In other words, a primary key exists for a strong entity set.
• Primary key of a strong entity set is represented by
underlining it.
Symbols Used:
• A single rectangle is used for representing a strong entity
set. =>
• A diamond symbol is used for representing the relationship
that exists between two strong entity sets.
• A single line is used for representing the connection of the
strong entity set with the relationship set.
• A double line is used for representing the total participation
of an entity set with the relationship set.
Example Strong Entity

In this ER Diagram:
-> Two strong entity sets “Student” and “Course” are related to each other.
-> Student ID is the primary key using which any student can be identified
uniquely.
-> Course ID is the primary key using which any course can be identified
uniquely.
-> Double line between Student and relationship set signifies total
participation.
It suggests that each student must be enrolled in at least one course.
-> Single line between Course and relationship set signifies partial
participation.
It suggests that there might exist some courses for which no enrollments are
made.
Weak Entity Sets
• In a relational database, a weak entity is an entity that
cannot be uniquely identified by its attributes alone;
therefore, it must use a foreign key in conjunction with
its attributes to create a primary key. The foreign key is
typically a primary key of an entity it is related to.
• A weak entity set is an entity set that does not contain
sufficient attributes to uniquely identify its entities. In
other words, a primary key does not exist for a weak
entity set. However, it contains a partial key called as a
discriminator. Discriminator can identify a group
of entities from the entity set.
• Discriminator is represented by underlining with a
dashed line.
Symbols Used Weak Entity Set
A double rectangle is used for representing a weak entity
set.
• A double diamond symbol is used for representing the
relationship that exists between the strong and weak
entity sets and this relationship is known as identifying
relationship.
• A double line is used for representing the connection of
the weak entity set with the relationship set.
• Total participation always exists in the identifying
relationship.
Example Weak Entity

In this ER Diagram:
-> One strong entity set “Building” and one weak entity set “Apartment”
are related to each other..
->Door number is the discriminator of the weak entity set “Apartment”.
->This is because door number alone can not identify an apartment
uniquely as there may be several other buildings having the same door
number.
->Double line between Apartment and relationship set signifies total
participation.
It suggests that each apartment must be present in at least one building.
->Single line between Building and relationship set signifies partial
participation.
It suggests that there might exist some buildings which has no apartment.
Entity Sets
 Entities can be represented graphically as follows:
• Rectangles represent entity sets.
• Attributes listed inside entity rectangle
• Underline indicates primary key attributes
Relationship Sets
 Diamonds represent relationship sets.
Cardinality Constraints
• 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
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,
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
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
E-R Diagram for a University
Enterprise
Examples of Creating ERD
 Example -1
 Scenario and
Generating ERD
Entity, Attribute and Relationship

 In a Building – Apartment renting scenario,


there are Apartments, building and
customer. There are multiple floors in the
building and on each floor there are multiple
apartments, floors can have zero or no
apartment. Each apartment can be rented at
most by one customer but customer can
rent out multiple apartments from same
building, apartment can be available on
multiple floor or same. At the end of month a
recipe is generated against which a rent is
deposited
Entity, Attribute and Relationship

Entities and Attributes:


 Building (bname, address, phone#)
 Floor (floor#, no_of_apartements)
 Apartment (aid, covered area, status(available
or rented), rent)
 Customer (cid, name, CNIC, contact # )
 Recipe (rid, apartment #, date_of_receipt,
amount)
Entity, Attribute and Relationship
Examples of Creating ERD
 Generating
Physical Models
From ERD
Entity, Attribute and Relationship
Entity, Attribute and Relationship

 Building(bname, address)
 Floor (floor #, no_apt, bname)

Assumption:
Floor# can be repeated among multiple building

 Customer (cid, name, address, contact#)

 Apartment(aid, status, floor#, bname, CA, cid)

 Receipt (rid, aid, cid,rent,dor)


Entity, Attribute and Relationship
 Example – 2:
Scenario and
Generating
ERD
Entity, Attribute and Relationship

 There are musical bands which record songs


and request musical companies to launch their
songs in the form of Album. Songs are written
by song writers. Album can contain at least
one song to be album and max of 12 songs.
Writer can write multiple songs but songs are
usually written irrespective of the number of
person in the bands.
Entity, Attribute and Relationship

• A university may have some departments.


All these departments employ various
lecturers and offer several programs. Some
courses make up each program. Students
register in a particular program and enroll in
various courses. A lecturer from the specific
department takes each course, and each
lecturer teaches a various group of
students.

You might also like