ENTITY AND ENTITY
SETS
PROF. P. N. JADHAV
Asst. Professor, RIT, Islampur
Outline
Entity
1. Tangible Entity
2. Intangible Entity
Entity Type
1. Strong Entity Type
2. Weak Entity Type
Entity Set
Attributes
[Link] attribute
[Link] attribute
[Link] attribute
[Link]-value attribute
[Link]-value attribute
Keys
Relationship
Relationship Set
Mapping Constrains
ENTITY
An entity is a real-world thing which can be distinctly identified
like a person, place or a concept.
An entity is an ‘object’ in the ‘actual world’, and that can be
identified from the other objects.
For example, in a school database, students, teachers, classes, and
courses offered can be considered as entities. All these entities
have some attributes or properties that give them their identity.
An Entity may be an object with a physical existence – a particular
person, car, house, or employee – or it may be an object with a
conceptual existence – a company, a job, or a university course.
ENTITY
Example: if we have a table of a student (roll_no,
student_name, age, mobile_no) then each student in that
table is an entity and can be uniquely identified by their roll
number i.e. roll_no.
ENTITY
1. Tangible entity
• Tangible entities are those entities which exist in the real
world physically. Example: person, car, etc.
2. Intangible entity
• Intangible entities are those entities which exist only
logically and have no physical existence.
• Example: bank account, University Courses, Job, etc.
ENTITY TYPE
• The entity type is a collection of the entity having similar
attributes.
• An Entity is an object of Entity Type
• In the above student table example, we have each row as an
entity and they are having common attributes i.E each row has its
own value for attributes roll_no, age, student_name and
mobile_no.
• So, we can define the above STUDENT table as an entity type
because it is a collection of entities having the same
attributes. So, an entity type in an ER diagram is defined by a
name(here, STUDENT) and a set of attributes(here, roll_no,
student_name, age, mobile_no).
ENTITY TYPE
• The table below shows how the data of different entities( different
students) are stored.
The E-R representation of the above Student Entity Type
is done below.
ENTITY
An Entity may be an object with a physical existence – a
particular person, car, house, or employee – or it may be
an object with a conceptual existence – a company, a job,
or a university course.
An Entity is an object of Entity Type
and set of all entities is called as entity
set. e.g.; E1 is an entity having Entity
Type Student and set of all students is
called Entity Set. In ER diagram,
Entity Type is represented as:
STRONG ENTITY TYPE
• Strong entity are those entity types which has a key attribute.
• The primary key helps in identifying each entity uniquely.
• It is represented by a rectangle.
• In the above example, roll_no identifies each element of the table
uniquely and hence, we can say that STUDENT is a strong entity
type.
WEAK ENTITY TYPE
• An entity that depends on another entity called a weak entity.
The weak entity doesn't contain any key attribute of its own.
Weak entity type can't be identified on its own. It depends
upon some other strong entity for its distinct identity.
• This can be understood with a real-life example. There can be
children only if the parent exits. There can be no independent
existence of children. There can be a room only if building
exits. There can be no independent existence of a room.
• A weak entity is represented by a double outlined rectangle.
WEAK ENTITY TYPE
For example 1 – a bank account cannot be uniquely identified
without knowing the bank to which the account belongs, so
bank account is a weak entity.
Example 2
WEAK ENTITY TYPE
Example: if we have two tables of customer(customer_id, name,
mobile_no, age, gender) and address(locality, town, state,
customer_id). Here we cannot identify the address uniquely as
there can be many customers from the same locality. So, for this,
we need an attribute of strong entity type i.e. ‘customer’ here to
uniquely identify entities of ‘address’ entity type.
ENTITY SET
• An entity set is a collection of similar types of entities. An
entity set may contain entities with attribute sharing similar
values.
• For example, a student’s set may contain all the students of a
school; likewise, a teachers set may contain all the teachers of
a school from all faculties.
EXAMPLE 1: IN THE BELOW EXAMPLE, TWO ENTITIES E1 (2,
ANGEL, 19, 8709054568) AND E2(4, ANALISA, 21, 9847852156)
FORM AN ENTITY SET.
ENTITY SET
Example 2: we can form another entity set by taking
three entities from the table. (2, angel, 19, 8709054568) ,
(3, priya, 20, 9864257315) and (4, analisa, 21,
9847852156) can also form a entity set. Similary, we can
form any combination of the entity set using any of the
entities from the entity type 'STUDENT'. Also, we can
understand that if we take all the records to the entity set
we get the entity type 'STUDENT'. So, we can say that the
entity type is the superset of the entity set.
ATTRIBUTES
Attributes are the properties which define the entity type.
For example, roll_no, name, DOB, age, address, mobile_no
are the attributes which defines entity type student.
In ER diagram, attribute is represented by an oval.
ATTRIBUTES
An attribute is a property or characteristic of an entity. An entity
may contain any number of attributes.
1. Simple attribute
Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic
value of 10 digits, the roll number of a student, the id number of an
employee.
ATTRIBUTES
2. Composite attribute
An attribute that can be split into components is a
composite attribute. An attribute composed of many other attribute
is called as composite attribute.
Example: The address can be further split into house number, street
number, city, state, country, and pin code, the name can also be split
into first name, middle name, and last name.
ATTRIBUTES
3. Derived attribute
An attribute that can be derived from other attributes is derived
attributes.
For example, the age attribute of an employee could be derived
from the date of birth attribute.
ATTRIBUTES
4. Single-value attribute
The attribute which takes up only a single value for each entity
instance is a single-valued attribute.
Example: the age of a student
ATTRIBUTES
5. Multi-value attribute
The attribute which takes up more than a single value for each
entity instance is a multi-valued attribute.
Example: Phone number of a student: Landline and mobile,
Email address
KEYS
• Keys play an important role in the relational database.
• Key is an attribute or collection of attributes that uniquely identifies
an entity among entity set.
• It is used to uniquely identify any record or row of data from the
table. It is also used to establish and identify relationships between
tables.
• For example, id is used as a key in the student table because it is
unique for each student. In the PERSON table, passport_number,
license_number, SSN ( SOCIAL SECURITY NUMBER) are keys since they
are unique for each person.
TYPES OF KEYS
Primary Key
Candidate Key
Super Key
Foreign Key
Alternate Key
Composite Key
PRIMARY KEY
o It is the first key used to identify one and only one instance of an
entity uniquely.
o An entity can contain multiple keys, as we saw in the PERSON
table. The key which is most suitable from those lists becomes a
primary key.
o For each entity, the primary key selection is based on requirements
and developers.
In the employee table, id can be
the primary key since it is
unique for each employee. In
the EMPLOYEE table, we can
even select license_number and
passport_number as primary
keys since they are also unique.
CANDIDATE KEY
o A candidate key is an attribute or set of attributes that can
uniquely identify a tuple.
o Except for the primary key, the remaining attributes are considered
a candidate key. The candidate keys are as strong as the primary
key.
For example: In the
EMPLOYEE table, id is best
suited for the primary key. The
rest of the attributes, like SSN,
Passport_Number,
License_Number, etc., are
considered a candidate key.
SUPER KEY
o Super key is an attribute set that can uniquely identify a tuple. A
super key is a superset of a candidate key.
For example: In the above EMPLOYEE
table, for (EMPLOEE_ID,
EMPLOYEE_NAME), the name of two
employees can be the same, but their
EMPLYEE_ID can't be the same.
Hence, this combination can also be a
key.
The super key would be EMPLOYEE-
ID (EMPLOYEE_ID, EMPLOYEE-
NAME), etc.
FOREIGN KEY
Foreign keys are the column of the table used to point to the
primary key of another table.
Every employee works in a specific department in a company,
and employee and department are two different entities. So we
can't store the department's information in the employee table.
That's why we link these two tables through the primary key of
one table.
We add the primary key of the DEPARTMENT table,
Department_Id, as a new attribute in the EMPLOYEE table.
In the EMPLOYEE table, Department_Id is the foreign key,
and both the tables are related.
ALTERNATE KEY
There may be one or more attributes or a combination of
attributes that uniquely identify each tuple in a relation. These
attributes or combinations of the attributes are called the
candidate keys.
One key is chosen as the primary key from these candidate
keys, and the remaining candidate key, if it exists, is termed the
alternate key.
In other words, the total number of the alternate keys is the
total number of candidate keys minus the primary key. The
alternate key may or may not exist. If there is only one
candidate key in a relation, it does not have an alternate key.
ALTERNATE KEY
Example 1:
Consider an EMPLOYEE_DETAIL table where we have the
following attributes:
Emp_SSN: The SSN number of employees is stored in this field.
Emp_Id: An attribute that stores the value of the employee
identification number.
Emp_name: An attribute that stores the name of the employee
holding the specified employee id.
Emp_email: An attribute that stores the email id of the specified
employees.
ALTERNATE KEY
ALTERNATE KEY
• These are the candidate keys we concluded from the above
attributes. Now, we have to choose one primary key, which is
the most appropriate out of the three, and it is Emp_Id.
• So, the primary key is Emp_Id. Now, the remaining two
candidate keys are Emp_SSN and Emp_email. Therefore,
Emp_SSN and Emp_Email are the alternate keys.
COMPOSITE KEY
• A 'combination of two or more' better describes the word
'composite'
• Whenever a primary key consists of more than one attribute,
it is known as a composite key. This key is also known as
Concatenated Key.
• A composite key is the DBMS key having two or more
attributes that together can uniquely identify a tuple in a table.
Such a key is also known as Compound Key, where each
attribute creating a key is a foreign key in its own right.
COMPOSITE KEY
• For example, in employee relations, we assume that an
employee may be assigned multiple roles, and an employee
may work on multiple projects simultaneously. So the primary
key will be composed of all three attributes, namely Emp_ID,
Emp_role, and Proj_ID in combination. So these attributes act
as a composite key since the primary key comprises more than
one attribute.
COMPOSITE KEY
Consider table A having three columns or attributes, which
are as follows:
Cust_Id: A customer id is provided to each customer who
visits and is stored in this field.
Order_Id: Each order placed by the customer is given an
order id, which is stored in this field.
Prod_code: It holds the code value for the products
available.
Prod_name: An attribute holding the name of the product
on the specified product code.
COMPOSITE KEY
• From the table, we found that no attribute is available that alone
can identify a record in the table and can become a primary key.
• However, the combination of some attributes can form a key and
can identify a tuple in the table.
• In the above example, Cust_Id and Prod_code can together form
a primary key because they alone are not able to identify a tuple,
but together they can do so.
COMPOSITE KEY
• The attribute Cust_Id can work as a primary key alone if the other
attributes which are identifiable through it are related to the
customer's details only, such as customer's phone number, name,
address, etc.
• Similarly, in the case of Prod_code, it fails to be a primary key alone
for this table because it can identify the Prod_name but cannot
identify the Cust_Id and Order_Id. Thus, we cannot make Prod_code
as the primary key.
• Both Cust_Id and Prod_code together can identify all the records of
the table because using such a combination, and we can identify the
Order_Id of the customer and also can identify the Prod_name of the
particular Prod_code.
• Therefore, {Cust_Id, Prod_code} is the composite key for the table.
RELATIONSHIP
• Relationships
Associations between entities are called relationships.
Example 1: An employee works for an organization. Here "works
for" is a relation between the entity’s employee and organization.
Example 2:
‘Enrolled in’ is a relationship that exists between entities Student
and Course.
1. An employee assigned a project.
2. Teacher teaches a student.
3. Author writes a book.
RELATIONSHIP SET
• A relationship set is a set of relationships of same type.
• Set representation of above ER diagram is-
The following relationship set depicts S1 is enrolled in C2, S2
is enrolled in C1 and S3 is enrolled in C3.
DEGREE OF A RELATIONSHIP SET
The number of different entity sets participating in a
relationship set is called as degree of a relationship
set.
TYPES OF RELATIONSHIP SETS
• On the basis of degree of a relationship set, a relationship set
can be classified into the following types-
UNARY RELATIONSHIP SET
When there is only ONE entity set
participating in a relation, the relationship is
called as unary relationship. For example, one
person is married to only one person.
BINARY RELATIONSHIP SET
Binary relationship set is a relationship set where two entity
sets participate in a relationship set.
For example, Student is enrolled in Course.
TERNARY RELATIONSHIP SET
Ternary relationship set is a relationship set where three entity
sets participate in a relationship set.
N-ARY RELATIONSHIP SET
N-ary relationship set is a relationship set where ‘n’ entity
sets participate in a relationship set.
MAPPING CONSTRAINS
• It defines the number of entities in one entity set, which can be
associated with the number of entities of other set via relationship
set.
One-to-one −
• One to one cardinality is represented by a 1:1 symbol. In this,
there is at most one relationship from one entity to another entity.
There are a lot of examples of one-to-one cardinality in real life
databases.
• For example, one student can have only one student id, and one
student id can belong to only one student. So, the relationship
mapping between student and student id will be one to one
cardinality mapping.
ONE-TO-ONE
Another example is the relationship between the director of the
school and the school because one school can have a maximum
of one director, and one director can belong to only one school.
One to one cardinality is represented by a 1:1 symbol.
ONE-TO-MANY
One-to-many − One entity from entity set A can be
associated with more than one entities of entity set B
however an entity from entity set B, can be associated with
at most one entity.
For Example, in a hospital, there can be various
compounders, so the relationship between the
hospital and compounders can be mapped through
One-to-many Cardinality.
ONE-TO-MANY
It can be represented by 1: M.
MANY-TO-ONE
Many-to-one − More than one entities from entity set A can
be associated with at most one entity of entity set B,
however an entity from entity set B can be associated with
more than one entity from entity set A.
• For example, there are multiple patients in a hospital who
are served by a single doctor, so the relationship between
patients and doctors can be represented by Many to one
Cardinality.
MANY-TO-ONE
It can be represented by M:1.
MANY-TO-MANY
Many-to-many − One entity from A can be associated with
more than one entity from B and vice versa.
• For Example, in a college, multiple students can
work on a single project, and a single student can
also work on multiple projects. So, the relationship
between the project and the student can be
represented by many to many cardinalities.
MANY-TO-MANY
It is represented by M: N or N: M.
Entity
Entity set
Attribute
Simple Attribute
Composite Attribute
Multivalued Attribute
Derived Attribute
Relationship
Weak Entity
Relationship
Weak Entity Set
End User
Database
Links
Strong Entity Set
h a n k
T
Y o u