Dbms Unit3
Dbms Unit3
For example, Suppose we design a school database. In this database, the student
will be an entity with attributes like address, name, id, age, etc. The address can be
another entity with attributes like city, street name, pin code, etc and there will be a
relationship between them.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can
be represented as rectangles.
43.9M
Highest Salary in SQL
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.
a. Key Attribute
c. 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.
d. 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.
Entity Set
A strong entity set is an entity set that contains sufficient attributes to uniquely
identify all its entities.
In other words, a primary key exists for a strong entity set.
Primary key of a strong entity set is represented by underlining it.
Symbols Used-
In this ER diagram,
Two strong entity sets “Student” and “Course” are related to each other.
Student ID and Student name are the attributes of entity set “Student”.
Student ID is the primary key using which any student can be identified uniquely.
Course ID and Course name are the attributes of entity set “Course”.
Course ID is the primary key using which any course can be identified uniquely.
Double line between Student and relationship set signifies total participation.
It suggests that each student must be enrolled in at least one course.
Single line between Course and relationship set signifies partial participation.
It suggests that there might exist some courses for which no enrollments are
made.
A weak entity set is an entity set that does not contain sufficient attributes to
uniquely identify its entities.
In other words, a primary key does not exist for a weak entity set.
However, it contains a partial key called as a discriminator.
Discriminator can identify a group of entities from the entity set.
Discriminator is represented by underlining with a dashed line.
NOTE-
The combination of discriminator and primary key of the strong entity set makes it
possible to uniquely identify all entities of the weak entity set.
Thus, this combination serves as a primary key for the weak entity set.
Clearly, this primary key is not formed by the weak entity set completely.
Symbols Used-
Example-
In this ER diagram,
One strong entity set “Building” and one weak entity set “Apartment” are related
to each other.
Strong entity set “Building” has building number as its primary key.
Door number is the discriminator of the weak entity set “Apartment”.
This is because door number alone can not identify an apartment uniquely as
there may be several other buildings having the same door number.
Double line between Apartment and relationship set signifies total participation.
It suggests that each apartment must be present in at least one building.
Single line between Building and relationship set signifies partial participation.
It suggests that there might exist some buildings which has no apartment.
Thus,
Primary key of Apartment
= Primary key of Building + Its own discriminator
= Building number + Door number
A single rectangle is used for the representation A double rectangle is used for the
of a strong entity set. representation of a weak entity set.
It contains sufficient attributes to form its It does not contain sufficient attributes to form
primary key. its primary key.
A diamond symbol is used for the A double diamond symbol is used for the
representation of the relationship that exists representation of the identifying relationship that
between the two strong entity sets. exists between the strong and weak entity set.
A single line is used for the representation of A double line is used for the representation of
the connection between the strong entity set the connection between the weak entity set and
and the relationship. the relationship set.
Total participation may or may not exist in the Total participation always exists in the
relationship. identifying relationship.
Important Note-
In ER diagram, weak entity set is always present in total participation with the identifying
relationship set.
So, we always have the picture like shown here-
Example-
‘Enrolled in’ is a relationship that exists between entities Student and Course.
Relationship Set-
Example-
The number of entity sets that participate in a relationship set is termed as the degree of
that relationship set. Thus,
On the basis of degree of a relationship set, a relationship set can be classified into the
following types-
1. Unary relationship set
2. Binary relationship set
3. Ternary relationship set
4. N-ary relationship set
Unary relationship set is a relationship set where only one entity set participates in a
relationship set.
Example-
One person is married to only one person
Binary relationship set is a relationship set where two entity sets participate in a
relationship set.
Example-
Student is enrolled in a Course
Ternary relationship set is a relationship set where three entity sets participate in a
relationship set.
Example-
N-ary relationship set is a relationship set where ‘n’ entity sets participate in a
relationship set.
Generalization
o Generalization is like a bottom-up approach in which two or more entities of
lower level combine to form a higher level entity if they have some attributes
in common.
o In generalization, an entity of a higher level can also combine with the entities
of the lower level to form a further higher level entity.
o Generalization is more like subclass and superclass system, but the only
difference is the approach. Generalization uses the bottom-up approach.
o In generalization, entities are combined to form a more generalized entity, i.e.,
subclasses are combined to make a superclass.
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 used to identify the subset of an entity set that shares some
distinguishing characteristics.
o Normally, the superclass is defined first, the subclass and its related attributes
are defined next, and relationship set are then added.
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.