02 ER Diagram
02 ER Diagram
Data Model
• 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
• 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
• 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
• 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.
• 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
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
• 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
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
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