Here, we will learn about the Components of the Entity-Relationship diagram with their types in detail.
The components of the ER diagram are the building blocks which help in creating the ER model. All the components have their own defined shapes or symbols which we have discussed in the previous article.
Following are the three main components of an ER diagram:
- Entity
- Attribute
- Relationship
Entity
An entity can be a real-world object either living or non-living like a person, place, concept, object, or event. In the Entity-Relationship diagram, the entity is denoted by the rounded rectangle box. All the entities have their properties which are called attributes in DBMS.
Following are the various examples of entity:
- ‘Student’ can be an entity,
- ‘Employee’ can be an entity,
- ‘Account’ can be an entity,
- ‘Hospital’ can be an entity,
- ‘Account’ can be an entity,
- ‘Car’ can be an entity,
- Registration can be an entity, etc.
Note: In the database table, each tuple is an entity.
For example, if we have an employee table, then each employee in that table is an entity. And, each employee is identified by the Employee_Id.
Entity Type
Entity Type is a set of entities having common properties. In the above table, we can define the name of the table as the entity type, i.e., ‘Student’ is the entity type. Because the ‘student’ table is a collection of entities having the same attribute.
Entity Set
Entity Set is a group of entities of the same entity type.
Following are the two different types of entity:
- Weak Entity
- Strong Entity
Weak Entity
A Weak entity is that entity which does not contain key attribute and depends on the strong entity via the foreign key. It is identified by some other strong entity using an identifying relationship.
In the Entity-Relationship diagram, a weak entity is represented by the double rectangle box.
Strong Entity
A Strong entity is that entity that contains a primary key attribute. This type of entity uniquely identifies its every record using the key attribute.
In the Entity-Relationship diagram, a strong entity is represented by the single rectangle box.
Attribute
An Attribute is a component which shows the properties or characteristics of an entity in the entity-relationship model. we can also assign the domain or range to the attribute.
In the entity-relationship diagram, attributes are represented by an oval or ellipse shape. In each diagram, every oval shape represents an attribute which is directly connected to an entity.
Following are the different types of attribute in the er model:
- Simple Attribute
- Key Attribute
- Derived Attribute
- Composite Attribute
- Multi-valued Attribute
Simple Attribute
Simple attributes are those attributes of an entity, which cannot be divided further into smaller components.
Following are the example of a simple attribute:
- Roll no of the Student can be a simple attribute,
- Id of the Employee can be a simple attribute,
- Salary of the Employee can be a simple attribute,
- Age and class of the student can be a simple attribute, etc.
Key Attribute
Key attribute (Primary Key) is an attribute which uniquely identifies all the entities in an entity set. The values of this attribute are distinct. In an Entity-Relationship diagram, this attribute is represented by the oval shape with the text underlined.
Following are the examples of key attribute:
- Roll no of the Student is a key attribute,
- Id of the Employee is a key attribute,
- Account Number of the customer in the banks, etc.
Derived Attribute
Derived Attributes are those attributes of an entity, which are based on other attributes and whose values are derived from other stored attributes. In an Entity-Relationship diagram, this attribute is represented by the dashed oval or ellipse shape.
Following are the examples of derived attribute:
- Age (Derived from Date of birth) of a student of an employee,
- Total or Average Marks of a student are derived attributes, etc.
Composite Attribute
Composite Attributes are those attributes of an entity, which is a combination of more than one attributes. In the Entity-Relationship diagram, this attribute is represented by an ellipse comprising of other ellipses.
Following are the examples of composite attribute:
- Address of an Employee is a composite attribute,
- The name of an Employee is a composite attribute, etc.
Multi-valued Attribute
Multi-valued Attributes are those attributes of an entity, which contain more than one value.
In the Entity-Relationship diagram, this attribute is represented by a double ellipse shape.
Following are the examples of multi-valued attribute:
- Mobile number of the Employee is a multi-valued attribute,
- Email_ID and address of the employee also be a multi-valued attribute, etc.
Relationship
A Relationship is also an important component of the ER model, which shows or describes the relationship between entities. Example: In the Entity-Relationship diagram, a relationship is represented by the diamond shape.
Following are the four different types of relationship in the ER model:
-
One-to-One Relationship
-
One-to-Many Relationship
-
Many-to-One Relationship
-
Many-to-Many Relationship
One-to-One Relationship
When one entity of the entity set P is related to a single entity of entity set Q, then this type of relation is called a one-to-one relationship. For example, An employee can work in only one department in an organization.
One-to-Many Relationship
When one entity of the entity set P is related to more than one entity of entity set Q, then this type of relation is called a one-to-many relationship. For example, One Employee can work in more than one department in an organization.
Many-to-One Relationship
When More than one entity of the entity set P is related to a single entity of entity set Q, then this type of relation is called a many-to-one relationship. For example, More than one Employee can work in one department in an organization.
Many-to-Many Relationship
When more than one entity of the entity set P is related to more than one entity of entity set Q, then this type of relation is called a many-to-many relationship. For example, More than one Employee can work in more than one department in an organization.