0% found this document useful (0 votes)
32 views72 pages

02 ER Diagram

The document provides a comprehensive overview of Entity-Relationship (ER) modeling, detailing various data models, attributes, entities, relationships, and their notations. It explains the concepts of weak entities, recursive relationships, and cardinality ratios, along with examples related to educational institutions and organizational structures. Additionally, it introduces Enhanced Entity-Relationship Diagrams (EERD) and discusses completeness and disjointness constraints in entity modeling.
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)
32 views72 pages

02 ER Diagram

The document provides a comprehensive overview of Entity-Relationship (ER) modeling, detailing various data models, attributes, entities, relationships, and their notations. It explains the concepts of weak entities, recursive relationships, and cardinality ratios, along with examples related to educational institutions and organizational structures. Additionally, it introduces Enhanced Entity-Relationship Diagrams (EERD) and discusses completeness and disjointness constraints in entity modeling.
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/ 72

Entity Relation Diagram

Data Model

• Collection of conceptual tools to describe the database


at a certain level of abstraction.
• Conceptual Data Model
• a high level description useful for requirements understanding.
• Entity-Relationship (ER) Model
• Representational Data Model
• describing the logical representation of data without giving details of physical
representation.
• Relational Data Model, Object-relational data model, Object-oriented data model,
Network Data Model, Hierarchical Data Model

• Physical Data Model


• description giving details about record formats, file structures etc.
• Frame memory model, Unifying Model
Database Modeling &
Implementation Process

• This is the predominant approach.


• ER Model is used to collect data requirements.
• ER model is mapped onto relational model.
• Relational model is implemented in a DBMS using Data
Definition Language (DDL).
• We will be looking at ER model and Relational model in
our course.
ER Model

• Widely used conceptual level data model.


• propose by Peter P Chen in 1970s.

• Concepts available in the model


• entities and attributes of entities.
• relationships between entities.
• diagrammatic notation.
Entity & Entity Set

• Entity:
• It is a person, place, thing and event about which we want to store
information.
• physical existence: person, car, house, room, chalk, book, or employee

• conceptual existence: course, company, job, section, ….
• Entity Set:
• collection of entities all having the same properties.
• Course entity set – collection of all course entities.
• Car entity set- collection of all car entities.
Attributes

• Each entity is described by a set of attributes/properties.


• Student entity
• Student Name - name of the student
• Idno - the idno of the student
• sex – the gender of the student
• All entities in an Entity Set have the same set of
attributes.
• Choosing set of attributes – depends on amount of detail
in modeling.
Entity, Entity Set & Attributes
Types of Attributes(1/2)

• Simple Attributes
• having atomic or indivisible values.
• e.g. course no, course title
• Composite Attributes
• having several components in the value.
• e.g. qualification (degreename, year, univname), studentName (first,
last, middle)
• Derived Attributes
• Attribute value is dependent on some other attribute.
• e.g. age depends on Date of Birth, annual increment depends on
basicSalary.
Types of Attributes(2/2)

• Single-valued
• having only one value rather than a set of values.
• e.g. course no, course title, dateOfBirth
• Multi-valued
• having a set of values rather than a single value.
• e.g. EmailAddress attribute of a student. Previousdegree attribute of a
student. CoursesEnrolled attribute of a student.
• Attributes can be
• simple single –valued.
• simple multi-valued.
• composite single-valued.
• composite multi-valued.
Diagrammatic Notation for
Entities
• entity
- rectangle
• attribute
- ellipse connected
to rectangle
• multi-valued attribute
- double ellipse
• composite attribute
- ellipse connected to
ellipse
• derived attribute
- dashed ellipse
Entity Set Examples

• Student entity set


Entity Set Examples

• Employee entity set


Domains of Attributes

• Set of values that may be assign to attribute is called


domains of attribute.
E.g. studentAge – {17,18, …… 55}
StudentName – {set of all characters} with length < 35
• Domain of composite attributes
• cross product of domains of component attributes
Entity Sets & Key Attributes

• Key
• an attribute or set of attributes that uniquely an entity in the entity set.
• E.g. RollNumber – Key for Student entity set
EmpId – Key for Faculty entity set
HostelName and RoomNo – key for Student entity set.
(assuming that each student gets to stay in a single room)
• A key may have more than one attribute i.e. section(section
number, course number), student(hostelname and RoomNo)
• An entity may have more than one key i.e. vehicle{registration
number, vehicle id), Student(SID, Addhar number).
• Keys should be minimum attributes.
Relationships

• When attribute of one entity refer to other entity is called


relationship. For example department in employee
entity refer to department in which employee works.
• When two or more entities are associated with each
other, we have an instance of a relationship.
• E.g. employee Ramesh works for department Marketing.
• Relationship works_for has Employee and Depertment
as the participating entity sets.
Works_For Relationship Set
Degree of a Relationship

• Degree: Describes the number of participating entities in


relationship.
• Degree 2 – binary (Employees works in department)
• Degree 3 – ternary ( supplier supplies a part to project)
• Degree n – n-ary
• Binary relationships are very common and widely used.
Diagrammatic Notation for
Relationships
• Relationship – diamond shaped box.
• Rectangle of each participating entity is connected by a line to this
diamond. Name of the relationship is written in the box.
Binary Relationships &
Cardinality Ratio

• The number of entities from E2 that an entity from E1 can


possible associate through R (and vice-versa)
determines the cardinality ratio of R.
• Four possibilities are usually specified.
• one-to-one (1:1)
• one-to-many (1:N)
• many-to-one (N:1)
• many-to-many (M:N)
Cardinality Ratios/ Multiplicity

• one-to-one (1:1)
• An E1 entity may be associated with at most one E2 entity and similarly
an E2 entity may be associated with at most one E1 entity.
• one-to-many (1:N)
• An E1 entity may be associated with many E2 entities whereas an E2
entity may be associated with at most one E1 entity.
• many-to-one (N:1)
• similar to above
• many-to-many (M:N)
• many E1 entities may be associated with a single E2 entity and a single
E1 entity may be associated with many E2 entities.
Cardinality Ratios Example –
one-to-one
– A Professor can teach utmost one course. A course can be taught by
utmost one professor.

– A student can reside in utmost one room. A room can accommodate


utmost one student.
Cardinality Ratios Example –
one -to-many/many-to-one
Cardinality Ratios Example –
many-to-many
Participation Constraints

• An entity set may participate in a relation either totally or


partially.
• Total participation: Every entity in the set is involved in some association
(or tuple) of the relationship.
• Partial participation: Not all entities in the set are involved in association
(or tuple) of the relationship.
Participation Constraints -
Example
Structural Constraints

• Cardinality Ratio and Participation Constraints are together


called Structural Constraints.
• They are called constraints as the data must satisfy them to
be consistent with the requirements.
• Min-Max notation: pair of numbers (m,n) placed on the line
connecting an entity to the relationship.
• m: the minimum number of times a particular entity must
appear in the relationship tuples at any point of time.
• 0 – partial participation
• >=1 – total participation
• n: similarly, the maximum number of times a particular entity
can appear in the relationship tuples at any point of time.
Attributes for Relationship
Types
• Relationship types can also have attributes.
• E.g.

• grade gives the letter grade (A, A-, B, B- …) earned by the student for a
course.
• it is neither an attribute of student nor that of course.
Attributes for Relationship
Types - Examples
Associative Entity
• An associative entity associates one or more entity(/entity type) and
contains attributes that are necessary to represent relationship.
• Relationship is many to many.
• It is represented in rounded rectangle.

Cardinality is changed
Recursive Relationships &
Role Names
• Recursive relationship: An entity itself is participant in
relationship is called recursive relationship.
Unary Relationship
Weak Entity Sets

• Weak Entity Set: An entity set whose members owe their


existence to some entity in a strong entity set.
• entities are not of independent existence.
• each weak entity is associated with some entity of the
owner entity set through a special relationship.
• weak entity set may not have a key attribute.
• Weak entity is represented in double line rectangle.
Weak Entity Set - example
Ternary Relationship

• Three entity participant simultaneously in relationship. i.e. Patient


receives treatment from physician. A suppliers supplies various parts to
various warehouse.
• Binary relationship can not be replaced with ternary relationship
because it has incomplete information.
Case

In an educational institute, there are several departments


and students belong to one of them. Each department
has a unique department number, a name, a location,
phone number and is headed by a professor. Professors
have a unique employee Id, name, phone number.
We like to keep track of the following details regarding
students: name, unique roll number, sex, phone number,
date of birth, age and one or more email addresses.
Students have a local address consisting of the hostel
name and the room number. They also have home
address consisting of house number, street, city and
PIN. It is assumed that all students reside in the hostels.
Case [2]
A course taught in a semester of the year is called a section.
There can be several sections of the same course in a
semester; these are identified by the section number. Each
section is taught by a different professor and has its own
timings and a room to meet. Students enroll for several
sections in a semester.
Each course has a name, number of credits and the department
that offers it. A course may have other courses as pre-
requisites i.e, courses to be completed before it can be
enrolled in.
Professors also undertake research projects. These are
sponsored by funding agencies and have a specific start date,
end date and amount of money given. More than one
professor can be involved in a project. Also a professor may
be simultaneously working on several projects. A project has a
unique projectId.
Entities

Student
Course
Section
Department
Professor
Project
Student entity set
Weak Entity Vs Composite-
Multivaued Attribute
• Note that section could be a composite multi-valued
attribute of Course entity.
• However, if so, section can not participate in
relationships, such as, enrolls with Student entity.
• In general, if a thing, even though not of independent
existence, participates in other relationships on its own, it
is best captured as a weak entity.
• If the above is not the case, composite multi-valued
attribute may be enough.
Relationships
• The company is organized into departments. Each department has a unique
name, a unique number, and a particular employee who manages the
department. We keep track of the start date when that employee began
managing the department. A department may have several locations.
• A department controls a number of projects, each of which has a unique name,
a unique number, and a single location.
• We store each employee’s name, Social Security number,2 address, salary, sex
(gender), and birth date. An employee is assigned to one department, but may
work on several projects, which are not necessarily controlled by the same
department. We keep track of the current number of hours per week that an
employee works on each project. We also keep track of the direct supervisor of
each employee (who is another employee).
• We want to keep track of the dependents of each employee supervisor of each
employee (who is another employee).
• We want to keep track of the dependents of each employee for insurance
purposes.We keep each dependent’s first name, sex, birth date, and
relationship to the employee
Acknowledgements

1. Pictures from Elmarsi R, & Navathe S B, Fundamental


of Database System, 5e, Pearson Education, 2008 are
used.
Enhanced Entity Relation
Diagram (EERD)
Requirement

• EERD Requirement
• EERD Type
• Constraints:
• Completeness Constraints
• Disjointness Constraints
• Subtype Discriminator
Three Choices:
1. Define general entity.
2. Define separate entity for each entity.
3. Define super type and sub type relationship.
EERD type

Super type: is generic entity that has relationship with one or


more sub type entity.
Sub type: is a special entity that has relationship or attributes
that are different than other subgroup.
Generalization is bottom up process. It defines more generic
entity from set of specialized entity.
Specialization is top down process. It is the process to
define one or more subclass of type super type.
When to use super/sub type relationship ? either (or both)
1. Attributes that apply to some entity instance
2. In some relationship subtype entity is participant. That is unique.
Generalization example
Generalization example
Completeness Constraints

Completeness Constraints: It answer the question an


instance of super type must be member of at least one
sub type or not. It specified by two rules:
Total participant: A total specialization constraint specifies
that every entity in the superclass must be a member of
at least one subclass in the specialization. This is shown
in EER diagrams by using a double line to connect the
superclass to the circle.
Partial participant: It allows an entity of superclass not to
belong any of its sub classes. This is shown in EER
diagrams by using a single line to connect the
superclass to the circle.
Disjointness constraint

A constraint that addresses the question whether an


instance of a super type may simultaneously be a
member of two (or more) subtypes. It has two possible
rules:
Disjoint rule: An entity instance of super type entity can be
member of only one sub type entity. It is represented as
D in circle.
Overlap rule: An entity instance of super type entity can be
participant more than one sub type entity. It is
represented as O in circle.
Defining sub type discriminators
An attribute of the super type whose values determine the target
subtype or subtypes.
Disjoint rule is specified by one attribute that is called predicate
defined subclass/ attribute define specialization.
Overlap rule is specified by composite type attribute that is called
user defined class.
Entity Relation Diagram
Example-1

Wada has a large collection of books. His friends borrow his books and he maintains a
list of friends, identified by unique FID and a list of book's, identified by BID. Each
friend has a name and has all the important telephone numbers which he can call to get
the book back. Each book has author name and title. Whenever a friend borrows a
book, he enters that fact into his/her database along with the date borrowed. Whenever
the book gets returned, that fact, too, gets noted along with the date returned. Draw an
ER diagram for the above description.
Solution
Exercise-1 (Recursive
Relation)
Question 1 : Suppose you are given the following requirements for a simple database for the
National Hockey League (NHL):
• NHL has many teams, each team has a name, a city, a coach, a captain, and a set of players,
• Each player belongs to only one team,
• Each player has a name, a position (such as left wing or goalie), a skill level, and a set of injury
records,
• A team captain is also a player,
• A game is played between two teams (referred to as host_team and guest_team) and has a date
(such as May 11th, 1999) and a score (such as 4 to 2).
Injuries
Name
Name City
Captain Coach Skill
Position
belongs
Team Player
1:1 1:M

Game Play

Date
Score
Ternary Relation

Rajasthan Roadways maintains several buses which run in


different routes. Each driver can be assigned to many
buses which goes to many routes (in different time slots).
Each bus that run in one or more route can be assigned
to many drivers, but each bus must be assigned to at
least one driver to a route. Each route can be reached by
many buses that is assigned to one or more drivers, but
each route must have at least one bus.
Driver Route
1:1 1:1
1:M
1:M
ASSIGNED
1:M

1:1

Buses
ERD
Design an ER schema for keeping track of information about votes taken in the
U.S.House of Representatives during the current two-year congressional session.
The database needs to keep track of each U.S. STATE’s Name (e.g., ‘Texas’, ‘New
York’, ‘California’) and include the Region of the state (whose domain is
{‘Northeast’, ‘Midwest’, ‘Southeast’, ‘Southwest’, ‘West’}). Each
CONGRESS_PERSON in the House of Representatives is described by his or her
Name, plus the District represented, the Start_date when the congressperson
was first elected, and the political Party to which he or she belongs (whose
domain is {‘Republican’, ‘Democrat’, ‘Independent’, ‘Other’}). The database keeps
track of each BILL (i.e., proposed law), including the Bill_name, the Date_of_vote
on the bill, whether the bill Passed_or_failed (whose domain is {‘Yes’, ‘No’}), and
the Sponsor (the congressperson(s) who sponsored—that is, proposed—the bill).
The database also keeps track of how each congressperson voted on each bill
(domain of Vote attribute is {‘Yes’, ‘No’, ‘Abstain’, ‘Absent’}). Draw an ER schema
diagram for this application. State clearly any assumptions you make.
Exercise-2
The company is organized into departments. Each department has a unique name, a unique
number, and a particular employee who manages the department. We keep track of the start
date when that employee began managing the department. A department may have several
locations.

A department controls a number of projects, each of which has a unique name, a unique
number, and a single location.

We store each employee’s name, Social Security number, address, salary, sex
(gender), and birth date. An employee is assigned to one department, but may work on several
projects, which are not necessarily controlled by the same department.
We keep track of the current number of hours per week that an employee works on each
project. We also keep track of the direct supervisor of each employee (who is another
employee).

We want to keep track of the dependents of each employee for insurance purposes. We keep
each dependent’s first name, sex, birth date, and relationship to the employee.
Exercise-3 EER
Draw an Enhanced Entity Relation diagram for the xyz Legal Company. Answer precisely as
per the given requirement without assumption.
The staff of the company consists of many lawyers and many legal assistants. The number of
staff is small enough that they can identify the staff by name. Each staff member has a role
(lawyer or legal assistant) and a salary. Each lawyer has a specialty like family lawyer,
property lawyer.

Lawyer fights cases for clients. Each case has case identification number and client name.

At least one lawyer, and possibly more, will work on each case, and each lawyer may work on
several cases (or on none). Every day, they record how much time they have worked on
each case.

Exactly one lawyer is assigned to be in charge of one case. Not all lawyers are in charge of a
case.

The legal assistants are assigned to cases; each legal assistant is assigned to at most one
case. A case may have more than one legal assistant assigned to it, and some cases have
no legal assistants at all.
Solution

You might also like