M1 Part 2 - ER Model
M1 Part 2 - ER Model
ER MODEL
• Entity Relationship Model
• ER model describes the structure of a database with the help of a diagram, which
is known as Entity Relationship Diagram (ER Diagram).
• Types of Attributes
4. Complex Attributes
• Example:
• For example, the ApartmentNumber attribute of an address applies
only to addresses that are in apartment buildings and not to other types
of residences, such as single-family homes.
Entity, Entity Types and Entity Set
• An entity type defines a collection of entities that have the same attributes.
• The collection of all entities of a particular entity type in the database at any
point in time is called an entity set.
Entity
11
Key Attributes of an Entity Type
Key Attributes
Key attributes identifies every entity in the entity set.
Key attributes will be having a unique value for each entity of that attribute.
Key attribute will never be a null valued attribute.
Any composite attribute can also be a key attribute.
There could be more than one key attributes for an entity type.
Domain
Domain of an attribute is the allowed set of values of that attribute.
if attribute is ‘grade’, then its allowed values are O,A,A+,B,B+
RELATIONSHIP
Relationship is an association between two or more entities of same or different entity set
For example,
TEACHER teaches STUDENTS
EMPLOYEE John works on P1 PROJECT or
EMPLOYEE Franklin manages the Research DEPARTMENT.
Each relationship has a name, degree and cardinality ratio.
WORK
EMPLOYEE PROJECT
S ON
MANAG
DEPARTMENT
ES
13
Relationship - Terminologies
• Relationship
• is an association between two or more entities of same or different
entity set
• Relationship Type
• Set of similar types of relationship.
• Relationship Set
• Set of relationships of the same type.
WORKS
EMPLOYEE DEPARTMENT
FOR
Set representation of ER
diagram
• Relationship : r1
PERSON MARRIED TO
Unary relationship
Ternary relationship
COURSE 17
Relationship Constraints or Structural
Constraints
• Relationship types usually have certain constraints.
1. Cardinality ratio
• Cardinality refers to the maximum number of times an instance in one entity can relate
to instances of another entity.
2. Participation Constraints
• specifies the minimum number of relationship instances that each entity can participate in.
Cardinality Ratio
• It tells how many instances of an entity type is related to one instance of the other entity.
1. one-to-one (1-1)
2. one-to-many (1-N)
3. many-to-one (M-1)
4. many-to-many (M-N)
Participation Constraints
• Recursive Relationship
24
Question 1:
• Construct an ER Diagram for Company having following details:
The company consist of different EMPLOYEEs. Company’s EMPLOYEE name, ssno,
address, salary, sex and birth date are recorded. An employee is assigned to one department,
but may work for several projects (not necessarily controlled by her dept). Number of
hours/week an employee works on each project is recorded. Every employee has an
immediate supervisor.
Company organized into DEPARTMENT. Each department has unique name and a particular
employee who manages the department. Start date for the manager is recorded. Department
may have several locations.
A department controls a number of PROJECT. Projects have a unique name, number and a
single location.
Employee’s DEPENDENT are tracked for health insurance purposes (dependent name,
birthdate, relationship to employee).
26
Question 2:
Design an Entity Relationship (ER) model for a college database. A college contains
many departments. Each department can offer any number of courses. Many
instructors can work in a department. An instructor can work only in one
department. For each department there is a Head. An instructor can be head of only
one department. Each instructor can take any number of courses. A course can be
taken by only one instructor. A student can enroll for any number of courses. Each
course can have any number of students.
Min-Max Notation
31