As we know that a database can be modeled as a collection of entities and relationships among entities.
ER Diagram stands for entity relationship diagram which helps us to explain the logical structure of databases.
An ER diagram looks like the flow chart but it consists of many more specializations like symbols and meaning of those symbols etc, which makes this model very unique.
In simple words, Entity Relationship Diagram(ERD) is a Graphical representation of the database structure.
The ER Diagram is also alternately known as Er models.
ER diagrams are created based on three basic concepts: entities, attributes, and relationships.
Components of ER-Diagram
An entity is an object that exists and is distinguishable from other objects. Entities are usually expressed by nouns
Specific person, company, event, plant, etc.
An entity set is a set of entities of the same type that share the same properties. Every entity is made up of some ‘attributes’ which represent that entity.
Set of persons, companies, trees, loansGroup pf person.
An entity is said to be a strong entity when it has a key attribute that can uniquely identify each instance of an entity.
The Strong Entity is not dependent upon any other entity for its existence in the database schema rather it has its own prime attribute. Strong Entity represented by a single rectangle.
Student_Id of student Emp_Id of employee
An entity does not have a primary key attribute and depends on another strong entity via a foreign key attribute. Weak Entity represented by a double rectangle.
A Room can only exist in a building.
An attribute describes the property of an entity. Attributes represented as Oval in an ER diagram. There are four types of attributes:
1. Key attribute
2. Composite attribute
3. Multivalued attribute
4. Derived attribute
Student = Student_id,Student_Name,Student_email
Course = Course_name,Course_id
The key attribute is also known as the prime attribute or primary key. A key attribute can uniquely identify an entity from an entity set.
Key attribute represented by oval same as other attributes however the text of key attribute is underlined.
The given diagram shows that student id is a key attribute.
An attribute that is a combination of other attributes is known as a composite attribute.
It is possible to break down composite attributes.
In a student entity, the student name is a composite attribute.
Student name divided into three parts i.e. first name, middle name, and last name.
As the name suggested this attribute has more than one single value.
It is represented with double ovals in an ER Diagram.
A student can have more than one phone number so the phone number attribute is multivalued.
Derived attributes are attributes whose value can be calculated from related attribute values and represented by a dashed oval in an ER Diagram.
The value of the derived attribute is not stored into the database since its values keep on changing and depend upon another attribute.
Student age is a derived attribute as it changes over time and can be derived from another attribute (Date of birth).
Relationships are associations between or among entities. Relationships are often expressed by verb phrases.
The relationship between the two entities is indicated by a diamond shape connected to the entities by a straight line.
There are four types of relationship:
- One to One.
- One to Many.
- Many to One.
- Many to Many.
One to One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to one relationship
For example, in a college database, each student has only one student ID, and each student ID is assigned to only one person.
One to Many Relationship
When one instance of entity of A can be associated with more than one instance of entity B known as the one to many relationships.
A student can study only in one department. But many students can study in one department.
Many to One Relationship
When more than one instance of an entity is associated with a single instance of another entity then it is called a many to one relationship.
Many students can study in a single college but a student cannot study in many colleges at the same time.
Many to Many Relationship
In many to many relationship many instance of entity A is associated with given instance of entity B. Similarly, many instance of entity B can be associated with a given instance of entity A.
A student can be assigned to many projects and a project can be assigned to many students.
ER modeling helps you to analyze data requirements systematically to produce a well-designed database. It’s considered best practice to complete ER modeling before implementing your database.