Module II: Relational Database & ER Model
Module II: Relational Database & ER Model
Module II: Relational Database & ER Model
Key Attribute –
The attribute which uniquely identifies each entity in the entity set is called key
attribute.For example, Roll_No will be unique for each student. In ER diagram,
key attribute is represented by an oval with underlying lines.
Composite Attribute –
An attribute composed of many other attribute is called as composite attribute.
For example, Address attribute of student Entity type consists of Street, City,
State, and Country. In ER diagram, composite attribute is represented by an oval
comprising of ovals.
Multivalued Attribute –
An attribute consisting more than one value for a given entity. For example,
Phone_No (can be more than one for a given student). In ER diagram,
multivalued attribute is represented by double oval.
Derived Attribute –
An attribute which can be derived from other attributes of the entity type is
known as derived attribute. e.g.; Age (can be derived from DOB). In ER diagram,
derived attribute is represented by dashed oval.
n-ary Relationship –
When there are n entities set participating in a relation, the relationship is
called as n-ary relationship.
Cardinality:
The number of times an entity of an entity set participates in a
relationship set is known as cardinality. Cardinality can be of different types:
One to one – When each entity in each entity set can take part only once in the
relationship, the cardinality is one to one. Let us assume that a male can marry to
one female and a female can marry to one male. So the relationship will be one to
one.
Many to one – When entities in one entity set can take part only once in the
relationship set and entities in other entity set can take part more than once in the
relationship set, cardinality is many to one. Let us assume that a student can take
only one course but one course can be taken by many students. So the cardinality
will be n to 1. It means that for one course there can be n students but for one
student, there will be only one course.
Many to many – When entities in all entity sets can take part more than once in
the relationship cardinality is many to many. Let us assume that a student can
take more than one course and one course can be taken by many students. So
the relationship will be many to many.
Participation Constraint:
Participation Constraint is applied on the entity participating in the relationship set.
1.Total Participation – Each entity in the entity set must participate in the
relationship. If each student must enroll in a course, the participation of student
will be total. Total participation is shown by double line in ER diagram.
2.Partial Participation – The entity in the entity set may or may NOT participate in
the relationship. If some courses are not enrolled by any of the student, the
participation of course will be partial.The diagram depicts the ‘Enrolled in’
relationship set with Student Entity set having total participation and Course
Entity set having partial participation.
Weak Entity Type and Identifying Relationship:
As discussed before, an entity type has a key attribute which uniquely identifies
each entity in the entity set. But there exists some entity type for which key
attribute can’t be defined. These are called Weak Entity type.
For example, A company may store the information of dependants (Parents,
Children, Spouse) of an Employee. But the dependents don’t have existence
without the employee. So Dependent will be weak entity type and Employee will
be Identifying Entity type for Dependant.
Definitions (con’t)
• A key attribute of an entity type is one
whose value uniquely identifies an entity of
that type.
• A combination of attributes may form a
composite key.
• If there is no applicable value for an
attribute that attribute is set to a null value.
Entity Type / Entity Set
WORKS_FOR
N 1
Name SSN . . .
EMPLOYEE DEPARTMENT
Supervision
Weak Entity Type
• A weak entity type is one without any key
attributes of its own. Entities belonging to a
weak entity type are identified by being
related to another entity type ( called
identifying owner) through a relationship
type ( called identifying relationship), in
combination with values of a set of its own
attributes (called partial key). A weak entity
type has total participation constraint w.r.t.
its identifying relationship.
Relationship Attributes
• Relationship types can have attributes as
well. in case of 1:1 or 1:N relationships,
attributes can be migrated to one of the
participating entity types.
Structural Constraints
• Structural constraints of a relationship
type:
– Cardinality ratio: Limits the number of
relationship instances an entity can participate
in, eg. 1:1, 1:N, M:N
– Participation constraint: If each entity of
an entity type is required to participate in
some instance of a relationship type, then that
participation is total; otherwise, it is partial.
Structural Constraint Min, Max
• A more complete specification of the
structural constraint on a relationship type
can be given by the integer pair (min,
max), which means an entity must
participate in at least min and at most max
relationship instances.
A ternary relationship generally represents
more information than 3 binary relationships
The ER Model has the power of expressing database entities in a conceptual
hierarchical manner. As the hierarchy goes up, it generalizes the view of
entities, and as we go deep in the hierarchy, it gives us the detail of every entity
included.
Going up in this structure is called generalization, where entities are clubbed
together to represent a more generalized view.
Specialization is the opposite of generalization. In specialization, a group of
entities is divided into sub-groups based on their characteristics. Take a
group ‘Person’ for example. A person has name, date of birth, gender, etc.
These properties are common in all persons, human beings. But in a
company, persons can be identified as employee, employer, customer, or
vendor, based on what role they play in the company.
The details of entities are generally hidden from the user; this process known
as abstraction.
Inheritance is an important feature of Generalization and Specialization. It allows
lower-level entities to inherit the attributes of higher-level entities.
For example, the attributes of a Person class such as name, age, and gender
can be inherited by lower-level entities such as Student or Teacher.
Aggregation
In aggregation, the relation between two entities is treated as a single entity. In aggregation,
relationship with its corresponding entities is aggregated into a higher level entity.
For example: Center entity offers the Course entity act as a single entity in the relationship
which is in a relationship with another entity visitor. In the real world, if a visitor visits a
coaching center then he will never enquiry about the Course only or just about the Center
instead he will ask the enquiry about both.
Steps to build ER Model
• Identify the entities and its types (gen. and spec., if
required)
• Identify the attributes associated with each entity and
the types of attributes
• Identify the relationship and its type between the
entities
• Identify the cardinality ratio/structural constraint
• Identify the type of participation
• Finally, represent the above steps through
appropriate symbols to make an ER model/diagram