M1 Part 2 - ER Model

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

Entity Relationship 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).

• An ER model is a design or blueprint of a database that can later be implemented


as a database.

• High level conceptual data model.

• Uses the concepts such as entities, attributes, and relationships.


Example:
Company Database
ENTITIES
• A “thing” in the real world with an independent existence.
• May be an object with physical existence (ex: house, person) or with
a conceptual existence(eg: course, job)
ATTRIBUTES
• Attributes
• Properties that describe the entities

• Types of Attributes

1. Composite vs Simple (Atomic) Attributes

2. Single-valued vs Multivalued Attributes

3. Stored vs Derived Attributes

4. Complex Attributes

5. NULL value Attributes


1) Composite vs Simple (Atomic) Attributes.

The value of a composite attribute is the concatenation of the values of


its constituent simple attributes
2) Single Valued vs Multivalued Attributes .
3. Derived vs Stored Attributes

For a particular person entity, the value of Age can be


determined from the current (today's) date and the value of that
person's BirthDate. The Age attribute is hence called a derived
attribute and is said to be derivable from the BirthDate attribute,
which is called a stored attribute.
4. Complex Attributes
5. Null Values
• Null is something which is unknown or not applicable.

• 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

• Relationship Type: WORKS_FOR

• Relationship Set: {r1, r2, r3, r4, r5, r6, r7} 15


Degree of a relationship type

• The degree of a relationship type is the number of participating


entity types.

1.Unary relationships – Relationship type of degree 1

2.Binary relationships – Relationship type of degree 2

3.Ternary relationships – Relationship type of degree 3


Degree of a Relationship Type

PERSON MARRIED TO
Unary relationship

WORKS Binary relationship


EMPLOYEE DEPARTMENT
FOR

TEACHER TEACHES STUDENT

Ternary relationship

COURSE 17
Relationship Constraints or Structural
Constraints
• Relationship types usually have certain constraints.

• Two main types of relationship 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

• There are 2 types of participation constraint:


1) Total participation:
• Every entity in the entity type participates in at
least one relationship in the relationship type.
• Represented by double lines.
2) Partial participation:
• Some entities may not participate in any
relationship in the relationship type.
• Represented by single line.
Role Names and Recursive Relationships
• Role names
• Each entity type that participates in a relationship
type plays a particular role in the relationship.
• The role name helps to explain what the
relationship entity type plays in each relation
• Not necessary in all relationships, but essential in
recursive relationships.

• Recursive Relationship

• Recursive Relationships - When there is a


relationship between two entities of the same type.

• In such cases the role name becomes essential for


distinguishing the meaning of the role that each
participating entity plays.
Strong and Weak Entities
Strong Entity:
• A strong entity is not dependent on any other entity in the schema.
• A strong entity will always have a primary key.
• Strong entities are represented by a single rectangle.
• The relationship of two strong entities is represented by a single diamond.
• Various strong entities, when combined together, create a strong entity set.
Weak Entity:
• A weak entity is dependent on a strong entity to ensure its existence.
• Unlike a strong entity, a weak entity does not have any primary key.
• It instead has a partial discriminator key.
• A weak entity is represented by a double rectangle.
• The relation between one strong and one weak entity is represented by a double
diamond. This relationship is also known as identifying relationship.
ER DIAGRAM
NOTATIONS
STRONG & WEAK ENTITY TYPES

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

• Min-max notation is an alternative representation for structural


constraints(ie’s cardinality and participation)
• This is an ordered pair of numbers (m, n) that appear on the
connecting line between the entities and their relationships.
• m - represents minimum number of times an entity can appear in a relation is
represented by m
• n - represents maximum number of times an entity can appear in a relation
is represented by m
• If m is 0 it signifies that the entity is participating in the relation partially,
whereas, if m is either greater than or equal to 1, it denotes total participation
of the entity.
Min-max notation example:
DESIGN CHOICES

• An attribute that exists in several entity types may be promoted to an


independent entity type.

• Inverse of the above case – If an entity type exists with a single


attribute & is related to only one other entity type, it may be demoted to
an attribute of the other entity type.

31

You might also like