Entity and Attributes

Divyansh Jain
Last Updated: May 13, 2022

Introduction

Entity and attributes are crucial aspects of RDBMS's ER model. If we have a collection of laptops that all belong to the same firm, are the same color, and have the exact specifications, we cannot distinguish them apart just on their looks.

And this is the reason why we are going to study Entity and Attributes because we must retrieve data from the database, and each of them must have a distinct value that may be used to distinguish between two sets of data. As a result, we can refer to an item as an entity when it becomes uniquely identifiable from the rest of the records in the database. So let's take a closer look at what an entity is, as well as entity sets and types. 

Entity

What is an Entity?

An entity is a distinct real-world thing, such as a person, a place, or a concept, that can be uniquely identified. It's an object that stands out from the crowd.

Before we move further, it is worth noting that an entity cannot be represented in an ER diagram since it is an instance/data. However, an entity-set can be represented as a rectangle in an ER diagram. An entity set is nothing but a set of similar attributes or properties. For example: Student Entity-set, Employee Entity-set, and so forth. 

Let us take an example to understand more: 

In the ER diagram below, we have two entity sets: Student and College, which have a many-to-one relationship since many students attend a single college. We'll go over relationships in more detail later; for now, let's concentrate on entities.

 

Types of Entity:

An entity can be of two types :

  • Tangible Entity: The term tangible entities refer to the physical entities that exist in the real world. 

Example: a student, a keyboard, a bank locker, car, etc.

  • Intangible Entity: Entities with solely a cognitive existence and no physical existence.   

Example: a Google Account, a bank account etc.

 

To better understand an Entity, let’s take some examples: 

  • A college student having a unique roll number is an entity.
  • An organization with a specific GST number can be considered an entity.
     

Example

In this particular example given below, we have a table named “Professor,” which contains multiple entities having attributes(Professor_ID, Professor_Name, Professor_City, Professor_Salary) by which we can understand that every entity contains a unique Professor_ID, which is the key attribute of the table which helps to distinguish between the entities.

<Professor>

Professor_IDProfessor_NameProfessor_CityProfessor_Salary
P01TomSydney$7000
P02DavidBrisbane$4500
P03MarkPerth$5000

 

Note: We don't represent the data in the E-R model. Instead, we represent the organization or schema. Data can be stored in tuples or rows and so represented as an entity when the E-R model is converted to a relational model.

Entity Type

With the Entity Data Model, the entity type is the essential building block for expressing the structure of data (EDM). An entity type in a conceptual model represents the structure of top-level notions like customers or orders. A template for entity type instances is an entity type.

An entity type is a group of the entity having similar attributes, which puts them in an entity type.

In the above Professor table example, each row was an entity and simultaneously had similar attributes. So, we can define the above “Professor” table as an entity type because it is a collection of entities having the same attributes.

Example: <Professor> is the Entity type in the example we used.

 

E-R representation of an Entity type:

Note: A rectangle outline is used to represent an entity type

Types of Entity type

  • Strong Entity Type
  • Weak Entity Type

Strong Entity type

A strong entity is one that is not reliant on other entities in the schema. A primary key is always present in a strong entity. A single rectangle represents a strong entity. A single diamond represents the bond between two powerful creatures.

When various strong entities are united, they form a strong entity set.

How to represent Strong Entity type:

For example:

                                                          Source: AfterAcademy

Weak Entity type

There is no key attribute for a weak entity type. It is unlikely to identify a weak entity type on its own. Its distinct identity is reliant on the presence of another strong entity. A real-life example can help you understand this: 

There can be children only if the parent exists. There can't be a separate existence for children. There can be a room only if the building exits. There can't be a room that exists on its own. 

A double-outlined rectangle represents a weak entity. An identifying connection is a relationship between a weak entity type and a strong entity type that is represented by a double outlined diamond rather than a single outlined diamond. The diagram below depicts this representation.

How to represent Weak Entity type:

For example: Here, we can see that “Address” is a weak entity as the whole entity can not be identified on its own just by using address entity type because it does not have any key attribute to identify the entity uniquely.

                                                                      Source: AfterAcademy

Entity Set

A group of entities with the same set of properties is referred to as an entity set. Each entity in an entity set has its own set of attribute values that distinguishes it from the other entities in the table. The characteristics of no two entities in an entity set will have identical values.

The Table in a database represents an entity set. The Student Table, which has numerous entities, is shown below. Even though both kids have the name Jhoson, they are uniquely identified since they have separate roll numbers.

                        Source: Binaryterms

Note: We can say that entity type is a superset of the entity set as all the entities are included in the entity type.

Example: Using three entities from the table, we may create a new entity set. An entity set can also consist of Angel, Priya, and Analisa. Similarly, any entity from the entity type 'STUDENT' can be used to create any combination of the entity set. Also, we can see that if we add all of the records to the entity set, the entity type 'STUDENT' is created. As a result, the entity type can be considered the superset of the entity set.

 

                                                                  Source: AfterAcademy

 

Now that you have understood what exactly is an entity in DBMS let us now have a look at the next subject, i.e, Attributes. 

Attributes

In general, an attribute is a characteristic. In a database management system (DBMS), an attribute refers to a database component, such as a table.

It also may refer to a database field. Attributes describe the instances in the column of a database.

A quality or characteristic of an entity is referred to as an attribute. An entity can have as many properties as it wants. One of the attributes is considered as the primary key. Attributes are expressed in an elliptical shape in an Entity-Relation model. Attributes in relational databases are the defining qualities or properties that define all objects belonging to a specific category and are applied to all cells in a column.

Example:  In a general Student table we can consider attributes like Roll No, Mobile No, and Age where we have Roll No as a key or primary attribute. 

Types Of Attributes:

 There are numerous types of attributes, including the following:

  • Simple Attribute & Composite Attribute
  • Single Valued Attribute & Multi-valued Attribute
  • Stored Attribute & Derived Attribute
  • Key Attribute & Non-key Attribute
     

Let’s discuss them one by one:

Simple Attribute & Composite Attribute

Simple attributes are the ones with atomic values, which cannot be divided further, while composite attributes consist of more than one simple attribute.

| Simple attribute:

A simple attribute has an atomic value that cannot be subdivided further. An oval is used to represent it. The entity type is directly linked to a basic attribute. The oval and the rectangle are immediately connected in the E-R diagram.

Example: The roll number of a student, age of a student, the id number of an employee.

| Composite attribute:

A Composite attribute can be further divided into other attributes. We show this in an E-R diagram by linking ovals, so the composite attribute is also represented by an oval, and then further divided attributes are all represented by ovals. We don't have any composite attribute columns when we convert this E-R diagram to a relational table. Only the attribute that came after we further separated the composite attribute has its own column.

Example: Just like the address of a house can be further divided into the house number, street number, city, state, country, and pin code. And the Name of a Student can be further divided into first name, middle name, and last name.

Single valued Attribute & Multi-valued Attribute

This divide is based on the attribute's ability to take multiple values. A multi-valued attribute is one that can accept more than one value. A single-valued attribute is one that accepts only one value.

| Single valued attribute:

There is only one value for this characteristic. A simple oval is used to represent it. A single-valued attribute can also be a basic attribute. The Section of 'Student,' for example, is a simple property because it cannot be further divided. Also, because a student cannot study in more than one section, it is a single-valued feature.

Example: The age of a student.

| Multi-valued attribute:

There are multiple values for this characteristic. A double oval is used to represent it. A multivalued attribute can be used with some Composite keys. The address property of a student, for example, can be further separated into 'Locality,' 'Town,' and 'PIN.'; as a result, we refer to it as a composite attribute. Furthermore, a student's address can have multiple values. A student can have multiple addresses, including both permanent and temporary addresses. As a result, it's also known as a multivalued characteristic.

Example: Email addresses, student’s phone number can be multiple in number, the addresses can be more than one.

 

Stored Attribute & Derived Attribute

This classification is based on whether the attribute is simply stored in the database or if it may be derived from another attribute.

| Stored attribute:

The user should give the value for this attribute. The value of this attribute is saved and can be used to find the value of other attributes. It isn't possible to get it from any other attribute. An oval is also used to represent it. The date of birth of 'Student,' for example, must be provided by the student.

Example: The Date of Birth of a student.

| Derived attribute:

This attribute's value is derived from the values of other characteristics. We know the value of another attribute (stored attribute) and are deriving the value of this attribute from the? We stored attributes (derived attributes). This is due to the fact that the value for such an attribute is constantly changing. A dashed oval is used to depict it.

Example: Just like the value of the age attribute is derived and extracted from the DOB(date of birth) attribute.

 

Key Attribute & Non-Key Attribute

This classification is based on whether or not the attribute may be used to uniquely identify the entities. As the name implies, key attributes will be able to uniquely identify entities, but non-key attributes will be unable to do so.

| Key attribute:

An entity type's entities are uniquely identified by a key attribute. A relational table represents the table's primary key. It is symbolized by an oval, and the text within it is highlighted. Even if all of an entity's other qualities are the same, the key attribute will always be unique.

For example: here, we have the Roll No of a student as a key attribute because a roll no cannot be the same for two students.

| Non-Key attribute:

The non-key attributes are all the other attributes that aren't the key attribute. This attribute can have the same value for two or more entities. For example, all students enrolled in the same class would have the same value for the Class attribute.

Example: the class, section, age, etc.

Frequently Asked Questions:

  1. What is the primary use of a key attribute in the table?
    A key attribute is used to help uniquely identify the entity from the entity set and helps to form a Strong entity type.
     
  2. How does a Strong entity differ from a weak entity?
    A strong entity set always has a primary key and is represented by a rectangle, while a weak entity does not have enough attributes to build a primary key and is represented by a double outlined rectangle symbol.
     
  3. How to identify an attribute from an E-R diagram?
    An attribute is always represented in an elliptical shape in an E-R model, while attributes are included to include details of the various entities that are highlighted in a conceptual ER diagram.

Key Takeaways

To summarise the article, we studied the entities that are uniquely identifiable and the entity type that is the superset of the entity set, and finally, the attributes that play a major role in the formation of the E-R relational model. Want to know more about SQL databases? We have various SQL topics covered, which you can refer to in our articles.

Don't stop here, Ninja; check out the Top 100 SQL Problems to get hands-on experience with frequently asked interview questions and land your dream job.

Happy Learning Ninja! 

Was this article helpful ?
0 upvotes

Comments

No comments yet

Be the first to share what you think