Entity and Entity Set Manuals
Entity and Entity Set Manuals
Entity set: An Entity is an object of Entity Type and a set of all entities is called
an Entity set.
Example: E1 is an entity having Entity Type Student and the set of all students
is called Entity Set.
If a student is an Entity, then the complete dataset of all the students will be
the Entity Set
BANK
2 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.
Components of ER Diagram
Entity
Simple rectangular box represents an Entity.
For example, id, age, contact number, name, etc. can be attributes of a student.
Attributes for any Entity
Ellipse is used to represent attributes of any entity. It is connected to the entity.
Types of Attributes
1.Key Attribute
The key attribute is used to represent the main characteristics of an entity. It
represents a primary key. The key attribute is represented by an ellipse with the
text underlined.
2.Composite 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.
4. Derived Attribute
For example, A person's age changes over time and can be derived from
another attribute like Date of birth.
To represent a derived attribute, another dotted ellipse is created inside the main
ellipse.
Relationship
1. Binary Relationship
2. Recursive Relationship
3. Ternary Relationship
ER Diagram: Binary Relationship
Binary Relationship means relation between two Entities. This is further divided
into three types.
Assume that a ‘Person’ (Id, Age, Name, Address) and a ‘Passport’ (Passport id, Passport no) are two
of the entities. As a result, each individual can only have one passport, and each passport can only
belong to one person.
A Company operates in only one Sector / each sector has many companies
operating in it.
Considering the above two rules or relationships, we see that although the
complete relationship involves three entities, but we are looking at two entities
at a time.
1. Total participation
2. Partial participation
1. Total Participation-
Itspecifies that each entity in the entity set must compulsorily participate
in at least one relationship instance in that relationship set.
That is why, it is also called as mandatory participation.
Total participation is represented using a double line between the entity
set and relationship set.
Example-
Here,
Double line between the entity set “Student” and relationship set
“Enrolled in” signifies total participation.
It specifies that each student must be enrolled in at least one course.
2. Partial Participation-
Itspecifies that each entity in the entity set may or may not participate in
the relationship instance in that relationship set.
That is why, it is also called as optional participation.
Partial participation is represented using a single line between the entity
set and relationship set.
Example-
Here,
Single line between the entity set “Course” and relationship set “Enrolled
in” signifies partial participation.
It specifies that there might exist some courses for which no enrollments
are made.
As the complexity of data increased in the late 1980s, it became more and more
difficult to use the traditional ER Model for database modelling. Hence some
improvements or enhancements were made to the existing ER Model to make it
able to handle the complex applications better.
1. Generalization
2. Specialization
3. Aggregation
Let's understand what they are, and why were they added to the existing ER
Model.
Generalization
It's more like Superclass and Subclass system, but the only difference is the
approach, which is bottom-up. Hence, entities are combined to form a more
generalised entity, in other words, sub-classes are combined to form a super-
class.
For example, Saving and Current account types entities can be generalised and
an entity with name Account can be created, which covers both.
Specialization
Specialization and generalization are fundamental concepts in database modeling that are useful for
establishing superclass-subclass relationships.
Specialization
Specialization is a top-down approach in which a higher-level entity is divided into
multiple specialized lower-level entities. In addition to sharing the attributes of the higher-level entity,
these lower-level entities have specific attributes of their own. Specialization is usually used to find subsets
of an entity that has a few different or additional attributes.
The following enhanced entity relationship diagram expresses the entities in a hierarchical database to
demonstrate specialization:
);
Generalization
-- Create the Vehicle table (General Entity Type with Specialization Attributes)
CREATE TABLE Vehicle (
Chassis_no VARCHAR(50) PRIMARY KEY,
Make VARCHAR(50),
Model VARCHAR(50),
stereo_present BOOLEAN,
seats_no INT,
load_capacity INT
);