Data modelling using ER model
Data modelling using ER model
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an
entity can be represented as rectangles.
a. Weak Entity
An entity that depends on another entity called a weak entity. The
weak entity doesn't contain any key attribute of its own. The weak
entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a
student.
b. Composite Attribute
b. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued
attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be
represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from
another attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or
rhombus is used to represent the relationship.
Types of relationship are as follows:
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then
it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to
one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance
of an entity on the right associates with the relationship then this is known
as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is
done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance
of an entity on the right associates with the relationship then it is known as a
many-to-one relationship.
For example, Student enrolls for only one course, but a course can have
many students.
c. Many-to-many relationship
When more than one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then it is
known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have
many employees.
Notation of ER diagram
Database can be
represented
using the
notations. In ER
diagram, many
notations are
used to express
the cardinality.
These notations
are as follows:
ER Diagram
ER Diagram stands for Entity Relationship Diagram, also known as ERD is a
diagram that displays the relationship of entity sets stored in a database. In other
words, ER diagrams help to explain the logical structure of databases. ER diagrams
are created based on three basic concepts: entities, attributes and relationships.
For example, Faculty and Student entities can be generalized and create a
higher level entity Person.
Specialization
o Specialization is a top-down approach, and it is opposite to
Generalization. In specialization, one higher level entity can be broken
down into two lower level entities.
o Specialization is
some
distinguishing
characteristics.
o Normally, the
attributes are
defined next,
and relationship
set are then
added.
For example: In an
Employee management system, EMPLOYEE entity can be specialized as
TESTER or DEVELOPER based on what role they play in the company.
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.
A relationship type R among n entity types E1, E2, ..., En defines a set of associa-
tions—or a relationship set—among entities from these entity types. As for the
case of entity types and entity sets, a relationship type and its corresponding rela-
tionship set are customarily referred to by the same name, R. Mathematically, the
relationship set R is a set of relationship instances ri, where
each ri associates n individual entities (e1, e2, ..., en), and each entity ej in ri is a
member of entity set Ej, 1 f j f n. Hence, a relationship set is a mathematical
relation on E1, E2, ..., En; alter-natively, it can be defined as a subset of the Cartesian
product of the entity sets E1 × E2 × ... × En. Each of the entity
types E1, E 2, ..., En is said to participate in the rela-tionship type R; similarly, each
of the individual entities e1, e2, ..., en is said to participate in the relationship
instance
ri =
(e1, e2, ...
, en).
Informally, each relationship instance ri in R is an association of entities, where the
association includes exactly one entity from each participating entity type. Each
such relationship instance ri represents the fact that the entities participating
in ri are related in some way in the corresponding miniworld situation. For
example, consider a relationship type WORKS_FOR between the two entity
types EMPLOYEE and DEPARTMENT, which associates each employee with
the department for which the employee works in the corresponding entity set. Each
relationship instance in the relationship set WORKS_FOR associates
one EMPLOYEE entity and one DEPARTMENT entity. Figure 7.9 illustrates this
example, where each relationship
Relationship types usually have certain constraints that limit the possible
combinations of entities that may participate in the corresponding relationship set.
These constraints are determined from the miniworld situation that the
relationships rep-resent. For example, in Figure 7.9, if the company has a rule that
each employee must work for exactly one department, then we would like to
describe this constraint in the schema. We can distinguish two main types of binary
relationship constraints: cardinality ratio and participation.
M:N.