0% found this document useful (0 votes)
18 views

Entity and Entity Set Manuals

The document discusses key concepts in entity relationship modeling including entities, attributes, relationships, and advanced concepts like generalization, specialization, and aggregation. Generalization involves combining lower level entities into a higher level entity in a bottom-up approach. Specialization breaks a higher level entity into more specialized lower level entities in a top-down manner. Aggregation treats a relationship between two entities as a single entity.

Uploaded by

aimlds.python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Entity and Entity Set Manuals

The document discusses key concepts in entity relationship modeling including entities, attributes, relationships, and advanced concepts like generalization, specialization, and aggregation. Generalization involves combining lower level entities into a higher level entity in a bottom-up approach. Specialization breaks a higher level entity into more specialized lower level entities in a top-down manner. Aggregation treats a relationship between two entities as a single entity.

Uploaded by

aimlds.python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Entity

An Entity is generally a real-world object which has characteristics and holds


relationships in a DBMS.

An entity may be any object, class, person or place

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

Considering the above example, Student is an entity, Teacher is an entity,


similarly, Class, Subject etc are also entities.
1 Strong Entity: Which does not dependent on another entity

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

Entitiy, Attributes, Relationships etc form the components of ER Diagram and


there are defined symbols and shapes to represent each one of them.

Let's see how we can represent these in our ER Diagram.

Entity
Simple rectangular box represents an Entity.

Relationships between Entities - Weak and Strong


Rhombus is used to setup relationships between two or more entities.
Attribute
Attributes are the characteristics or properties that describe the entities. They provide more
detailed information about each entity. Attributes are represented as ovals connected to their
respective entities.

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 that composed of many other attributes is known as a composite


attribute. The composite attribute is represented by an ellipse, and those ellipses
are connected with an ellipse.
3. 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.

4. 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.

To represent a derived attribute, another dotted ellipse is created inside the main
ellipse.
Relationship

A Relationship describes relation between entities. Relationship is represented


using diamonds or rhombus.

There are three types of relationship that exist between Entities.

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.

One to One Relationship


This type of relationship is rarely seen in real world.

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.

Using Sets, it can be represented as


One to Many Relationship
The below example showcases this relationship, which means that 1 student can
opt for many courses, but a course can only have 1 student. Sounds weird! This
is how it is.

Using sets, one-to-many cardinality can be represented as:

Many to One Relationship


It reflects business rule that many entities can be associated with just one entity.
For example, Student enrolls for only one Branch but a Course can have many
Students.
Using Sets, it can be represented as:

Many to Many Relationship


The above diagram represents that one student can enroll for more than one
courses. And a course can have more than 1 student enrolled in it.

Using Sets, it can be represented as:

ER Diagram: Recursive Relationship

When an Entity is related with itself it is known as Recursive Relationship.


Ternary Relationship

Relationship of degree three is called Ternary relationship.

A Ternary relationship involves three entities. In such relationships we always


consider two entites together and then look upon the third.
For example, in the diagram above, we have three related
entities, Company, Product and Sector. To understand the relationship better
or to define rules around the model, we should relate two entities and then
derive the third one.

A Company produces many Products/ each product is produced by exactly one


company.

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.

Cardinality refers to the maximum number of times an instance in one entity


can relate to instances of another entity.
Cardinality and ordinality are shown by the styling of a line and its endpoint,
according to the chosen notation style.
Types of Participation Constraints-

There are two types of participation constraints-

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.

Relationship between Cardinality and Participation Constraints-

Minimum cardinality tells whether the participation is partial or total.


 If minimum cardinality = 0, then it signifies partial participation.
 If minimum cardinality = 1, then it signifies total participation.
Maximum cardinality tells the maximum number of entities that participates in
a relationship set.
Generalization

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.

Hence, as part of the Enhanced ER Model, along with other improvements,


three new concepts were added to the existing ER Model, they were:

1. Generalization
2. Specialization
3. Aggregation
Let's understand what they are, and why were they added to the existing ER
Model.

Generalization

Generalization is a bottom-up approach in which two lower level entities


combine to form a higher level entity. In generalization, the higher level entity
can also combine with other lower level entities to make further higher level
entity.

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 is opposite to Generalization. It is a top-down approach in which


one higher level entity can be broken down into two lower level entity. In
specialization, a higher level entity may not have any lower-level entity sets, it's
possible.
Aggregation

Aggregation is a process when relation between two entities is treated as


a single entity.
In the diagram above, the relationship between Center and Course together, is
acting as an Entity, which is in relationship with another entity Visitor. Now in
real world, if a Visitor or a Student visits a Coaching Center, he/she will never
enquire about the center only or just about the course, rather he/she will ask
enquire about both.

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:

-- Create the Vehicle table (General Entity Type)


CREATE TABLE Vehicle (
Chassis_no VARCHAR(50) PRIMARY KEY,
Make VARCHAR(50),
Model VARCHAR(50)
);

-- Create the Car table (Specialized from Vehicle)


CREATE TABLE Car (
Chassis_no VARCHAR(50) PRIMARY KEY,
stereo_present BOOLEAN,
FOREIGN KEY (Chassis_no) REFERENCES Vehicle(Chassis_no)
);

-- Create the Bus table (Specialized from Vehicle)


CREATE TABLE Bus (
Chassis_no VARCHAR(50) PRIMARY KEY,
seats_no INT,
FOREIGN KEY (Chassis_no) REFERENCES Vehicle(Chassis_no)
);

-- Create the Truck table (Specialized from Vehicle)


CREATE TABLE Truck (
Chassis_no VARCHAR(50) PRIMARY KEY,
load_capacity INT,
FOREIGN KEY (Chassis_no) REFERENCES Vehicle(Chassis_no)

);
Generalization

Generalization is a bottom-up approach in which multiple lower-level entities are combined


to form a single higher-level entity. Generalization is usually used to find common attributes
among entities to form a generalized entity. It can also be thought of as the opposite of
specialization.

The following enhanced entity relationship diagram expresses entities in a hierarchical


database to demonstrate 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
);

-- Inserting some sample data into the Vehicle table


INSERT INTO Vehicle (Chassis_no, Make, Model, stereo_present, seats_no, load_capacity) VALUES
('ABC123', 'Toyota', 'Camry', TRUE, NULL, NULL), -- Car
('DEF456', 'Volvo', 'XC90', FALSE, 7, NULL), -- Bus
('GHI789', 'Ford', 'F-150', NULL, NULL, 2000); -- Truck

You might also like