Dbms Unit5.

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

UNIT-5

EER AND ER to relational mapping


What are the ER diagrams?
ER diagram is a visual representation of data based on the ER model, and it describes how entities are related to each other in the
database.

What are EER diagrams?


EER diagram is a visual representation of data, based on the EER model that is an extension of the original entity-
relationship (ER) model.

Entity
An entity is any singular, identifiable and separate object. It refers to individuals, organizations, systems, bits of data or even distinct
system components that are considered significant in and of themselves. For example, People, Property, Organizations, Agreements
and, etc. In the ER diagram, the entity is represented by a rectangle.

Weak Entity
A weak entity is an entity that depends on the existence of another entity. In more technical terms it can be defined as an entity that
cannot be identified by its own attributes.

Attributes

Attributes are the properties that define the entity type. For example, Roll_No, Name, DOB, Age, Address, Mobile_No are
the attributes that define entity type Student. In the ER diagram, the attribute is represented by an oval.

Multi-valued Attribute
If an attribute can have more than one value it is called a multi-valued attribute.

Derived Attribute
An attribute-based on another attribute.

Relationships
A relationship is an association that describes the interaction between entities.

Recursive Relationship
If the same entity participates more than once in a relationship it is known as a recursive relationship.
Cardinality
Cardinality refers to the maximum number of times an instance in one entity can relate to instances of another entity. There are three
types of cardinalities.
1. one to one (1 to 1)
2. one to many(1 to N)
3. many to many (M to N)

Participation
Participation constraint specifies the existence of an entity when it is related to another entity in a relationship type. There are two
types. Partial and Total participation.
Total Participation − Each entity is involved in the relationship. Total participation is represented by double lines.
Partial participation − Not all entities are involved in the relationship. Partial participation is represented by single lines.

Below points show how to go about creating an ER diagram.


1. Identify all the entities in the system. An entity should appear only once in a particular diagram. Create rectangles for all entities
and name them properly.
2. Identify relationships between entities. Connect them using a line and add a diamond in the middle describing the relationship.
3. Add attributes for entities. Give meaningful attribute names so they can be understood easily.
4. Mark the cardinalities and participation between the entities.
Here is an example of ER diagrams.
Now let’s see how to draw EER diagrams.
Here we just need to add a few things to above.
1. As in drawing ER diagrams first, we have to identify all entities.
After we found entities from the scenario you should check whether those entities have sub-entities. If so you have to mark sub-
entities in your diagram.
Dividing entities into sub-entities we called as specialization. And combining sub-entities to one entity is called a generalization.

2. Then you have to identify relationships between entities and mark them.


3. Add attributes for entities. Give meaningful attribute names so they can be understood easily.
4.Mark the cardinalities and participation
If it is an EER diagram you have to add a few to your diagram.
Here also we have to check whether sub-entities totally depend on the main entity or not. And you should mark it.
If all members in the superclass(main entity) participate in either one subclass it is known as total participation. It marks by double
lines.

Total ParticipationIf at least one member in the superclass does not participate in subclass it is known as partial participation. It
is denoted by one single line.
Partial ParticipationIf all the members in the superclass participate for only one subclass it is known as disjoint and denoted by
“d”. If all the members in the superclass participate in more than one subclass it is known as overlap and denoted by “o”.
Now it ends, after following all the above steps you can come up with your ER and EER diagrams.😍
Benefits of ER and EER diagrams.
 Easy to understand and does not require a person to undergo extensive recently training to be able to work with it and accurately.
 Readily translatable to relational tables which can be used to quickly build databases
 Can directly be used by database developers as the blueprint for implementing databases in specific software application
 It can be applied in other contexts such as describing the different relationships and operations within an organization.

Mapping ER diagrams into relational schemas

Follow the steps one by one to get it done.🤞


1. Mapping strong entities.
2. Mapping weak entities.
3. Map binary one-to-one relations.
4. Map binary one-to-many relations
5. Map binary many-to-many relations.
6. Map multivalued attributes.
7. Map N-ary relations
1. Mapping strong entities.
2. Mapping weak entities.

Above it shows an ER diagram with its relationships. You can see there are two strong entities with relationships and a weak entity with a
weak relationship.
When you going to make a relational schema first you have to identify all entities with their attributes. You have to write attributes in
brackets as shown below. Definitely you have to underline the primary keys. In the above DEPENDENT is a weak entity. To make it
strong go through the weak relationship and identify the entity which connects with this. Then you have written that entity’s primary key
inside the weak entity bracket.
Then you have to map the primary key to where you took from as shown below.

3. Map binary one to one relations.Let’s assume that the relationship between CUSTOMER and CARD is one to one.There are three
occasions where one to one relations take place according to the participation constraints.
I. Both sides have partial participation.

When both sides have partial participation you can send any of the entity’s primary key to others. At the same time, if there are attributes
in the relationship between those two entities, it is also sent to other entity as shown above.

So, now let us see how we write the relational schema.

Here you can see I have written CUSTID and STARTDATE inside the CARD table. Now you have to map CUSTID from where it
comes. That’s it.🤩

II. One side has partial participation.

You can see between the relationship and CARD entity it has total participation.

When there is total participation definitely the primary of others comes to this. And also if there are attributes in the relationship it also
comes to total participation side.

Then you have to map them as below.

III. Both sides have total participation


If both sides have total participation you need to make a new relationship with a suitable name and merge entities and the relationship.

Following it shows how we should write the relation.

Now let us see how to map one to many relations.

4. Map binary one-to-many relations

If it is one-to-many, always to the many side other entities' primary keys and the attributes in the relationship go to the many side. No
matter about participation. And then you have to map the primary key.

5. Map binary many to many relations.

If it is many to many relations you should always make a new relationship with the name of the relationship between the entities.

And there you should write both primary keys of the entities and attributes in the relationship and map them to the initials as shown
below.
6. Map multivalued attributes.

If there are multivalued attributes you have to make a new relationship with a suitable
name and write the primary key of the entity which belongs to the multivalued attribute and also the name of the multivalued attribute as
shown below.

7. Map N-ary relations.


First, let us consider unary relationships.We categorized them into two.

I. one-to-one and one to many relations.

If it is unary and one to one or one to many relations you do not need to make a new relationship you just want to add a new primary key
to the current entity as shown below and map it to the initial. For example, in the above diagram, the employee is supervised by the
supervisor. Therefore we need to make a new primary key as SID and map it to EMPID. Because of SID also an EMPID.

II. many-to-many relations.


If it is unary and many to many relations you need to make a new relationship with a suitable name. Then you have to give it a proper
primary key and it should map to where it comes as shown below.

Now let us see how to map relations with more than two entities.

If there are more than three entities for a relationship you have to make a new relation table and put all primary keys of
connected entities and all attributes in the relationship. And in the end, you have to map them as shown below.

You might also like