ER Diagram
ER Diagram
An Entity Relationship Diagram (ER Diagram) pictorially explains the relationship between entities to be
stored in a database. Fundamentally, the ER Diagram is a structural design of the database. It acts as a
framework created with specialized symbols for the purpose of defining the relationship between the
database entities. ER diagram is created based on three principal components: entities, attributes, and
relationships.
The following diagram showcases two entities - Student and Course, and their relationship. The
relationship described between student and course is many-to-many, as a course can be opted by several
students, and a student can opt for more than one course. Student entity possesses attributes - Stu_Id,
Stu_Name & Stu_Age. The course entity has attributes such as Cou_ID & Cou_Name.
What is an ER Model?
An Entity-Relationship Model represents the structure of the database with the help of a diagram. ER
Modelling is a systematic process to design a database as it would require you to analyze all data
requirements before implementing your database.
Weak Entity
• An entity that makes reliance over another entity is called a weak entity
• You showcase the weak entity as a double rectangle in ER Diagram.
• In the example below, school is a strong entity because it has a primary key attribute - school
number. Unlike school, the classroom is a weak entity because it does not have any primary key
and the room number here acts only as a discriminator.
Attribute
• An attribute exhibits the properties of an entity.
• You can illustrate an attribute with an oval shape in an ER diagram.
Key Attribute
Multivalued Attribute
• Some attributes can possess over one value, those attributes are called multivalued attributes.
• The double oval shape is used to represent a multivalued attribute.
Derived Attribute
• An attribute that can be derived from other attributes of the entity is known as a derived attribute.
• In the ER diagram, the dashed oval represents the derived attribute.
Relationship
One-to-One Relationship
• When a single element of an entity is associated with a single element of another entity, it is called
a one-to-one relationship.
• For example, a student has only one identification card and an identification card is given to one
person.
One-to-Many Relationship
• When a single element of an entity is associated with more than one element of another entity, it is
called a one-to-many relationship
• For example, a customer can place many orders, but an order cannot be placed by many
customers.
Many-to-One Relationship
• When more than one element of an entity is related to a single element of another entity, then it is
called a many-to-one relationship.
• For example, students have to opt for a single course, but a course can have many students.
Many-to-Many Relationship
• When more than one element of an entity is associated with more than one element of another
entity, this is called a many-to-many relationship.
• For example, you can assign an employee to many projects and a project can have many
employees.
STUDENT
id
Name
cgpa
Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles; they specify how employee entities interact
via the works-for relationship set.
• Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles.
• Role labels are optional, and are used to clarify semantics of the relationship
• Relationship sets that involve two entity sets are binary (or degree two). Generally, most
relationship sets in a database system are binary.
• Relationships between more than two entity sets are rare. Most relationships are binary.