RDBMS Unit2 Erd
RDBMS Unit2 Erd
Here we will discuss how choosing an entity set vs an attribute can change
the whole ER design semantics.
To understand this lets take an example, let’s say we have an entity set
Student with attributes such as student-name and student-id.
Now we can say that the student-id itself can be an entity with the
attributes like student-class and student-section.
Now if we compare the two cases, in the first case we can say that the
student can have only one student id, however in the second case when we
chose student id as an entity it implied that a student can have more than
one student id.
To decide the perfect choice between these two (entity vs relationship), the
user needs to understand whether the entity would need a new
relationship if a requirement arise in future, if this is the case then it is
better to choose entity set rather than relationship set.
This is fine until there is a need to disburse a joint loan, in such case a new
relationship needs to be created to define the relationship between the two
1
individuals who have taken joint loan. In this scenario, it is better to choose
loan as an entity set rather than a relationship set.
The n-ary relationships are those where entity sets are more than two, if
the entity sets are only two, their relationship can be termed as binary
relationship.
The n-ary relationships can make ER design complex, however the good
news is that we can convert and represent any n-ary relationship using
multiple binary relationships.
2
The basic rules for converting the ER diagrams
into Relational Database ( tables) are-
Convert all the Entities in the diagram to tables. All the entities
represented in the rectangular box in the ER diagram become
independent tables in the database.
All single valued attributes of an entity is converted to a column of
the table. All the attributes, whose value at any instance of time is
unique, are considered as columns of that table
Key attribute in the ER diagram becomes the Primary key of the
table.
Declare the foreign key column, if applicable
Any multi-valued attributes are converted into new table
Any composite attributes are merged into same table as different
columns.
One can ignore derived attribute, since it can be calculated at any
time.
3
Definition:
4
Design an ER diagram for the following scenario:
A COMPANY Database
5
It displays the COMPANY ER database schema as
an ER diagram. We now review the full ER
diagram notation.
Entity types such as EMPLOYEE, DEPARTMENT, and PROJECT are
shown in rectangular boxes.
Relationship types such as WORKS_FOR, MANAGES, CONTROLS,
and WORKS_ON are shown in diamond-shaped boxes attached to the
participating entity types with straight lines.
Attributes are shown in ovals, and each attribute is attached by a
straight line to its entity type or relationship type.
Component attributes of a composite attribute are attached to the
oval representing the composite attribute, as illustrated by the Name
attribute of EMPLOYEE.
Multivalued attributes are shown in double ovals, as illustrated by
the Locations attribute of DEPARTMENT.
Key attributes have their names underlined.
Derived attributes are shown in dotted ovals, as illustrated by
the Number_of_employees attribute of DEPARTMENT.
Weak entity types are distinguished by being placed in double
rectangles and by having their identifying relationship placed in
double diamonds, as illustrated by the DEPENDENT entity type and
the DEPENDENTS_OF identifying relationship type.
The partial key of the weak entity type is underlined with a dotted
line.
The cardinality ratio of each binary relationship type is specified by
attaching a 1, M, or N on each participating edge.
The cardinality ratio of DEPARTMENT: EMPLOYEE in MANAGES is
1:1, whereas it is 1: N for DEPARTMENT: EMPLOYEE in WORKS_FOR,
and M:N for WORKS_ON.
6
The participation constraint is specified by a single line for partial
participation and by double lines for total participation (existence
dependency).
We show the role names for the SUPERVISION relationship type
because the same EMPLOYEE entity type plays two distinct roles in
that relationship. Notice that the cardinality ratio is 1:N from
supervisor to supervisee because each employee in the role of
supervisee has at most one direct supervisor, whereas an employee
in the role of supervisor can supervise zero or more employees.
https://beginnersbook.com/2021/07/dbms-er-diagram-to-
table-conversion/