Introduction to Entity Relationship Diagrams (ERD)

Entity Relationship Diagrams

An Entity Relationship Diagrams (ERD) is a visual representation used to model the data within a system and how different pieces of data are related. The concept of ERDs was introduced by Peter Chen in 1976 to help in the design and modeling of databases. The primary purpose of an ERD is to describe the data requirements and relationships for a system in a clear and structured manner. It is widely used in database design, particularly in relational databases, but can also be applied to other forms of system modeling.

ERDs are useful tools for system designers, software developers, database administrators, and business analysts. They are essential for developing and optimizing databases, as they provide a blueprint of the system’s data structure.


Components of an Entity Relationship Diagrams (ERD)

The core components of an Entity-Relationship Diagram include entities, attributes, relationships, and cardinality. These components allow you to break down a system’s data into manageable and understandable pieces.

1. Entities

An entity represents a real-world object, concept, or event that has significance in the system and about which data is stored. In simple terms, entities are things that are “important” enough to be represented as objects in a system.

  • Example: A Customer is an entity in an online shopping system. Other examples include Product, Order, Payment, etc.

Representation in ERD:

  • Entities are typically represented as rectangles.
  • The name of the entity is written inside the rectangle (usually a noun, like Customer, Product).

2. Attributes

An attribute is a property or characteristic that further describes an entity. Each entity may have several attributes.

  • Example: For the Customer entity, attributes might include Customer ID, Name, Address, Phone Number, etc.

Representation in ERD:

  • Attributes are typically represented as ovals (ellipses) connected to their respective entities by a line.
  • The attribute names are written inside the ovals.

Types of Attributes:

  • Simple Attributes: Single atomic value (e.g., Customer Name).
  • Composite Attributes: Can be divided into smaller sub-parts (e.g., Full Name could be divided into First Name and Last Name).
  • Derived Attributes: Attributes whose values can be derived from other attributes (e.g., Age can be derived from Date of Birth).
  • Multi-valued Attributes: Attributes that can have multiple values (e.g., Phone Numbers could have several phone numbers for one Customer).

3. Relationships

A relationship is a connection between two or more entities that shows how they are related in the system.

  • Example: A Customer places an Order (one-to-many relationship), an Order contains multiple Products (many-to-many relationship), or a Customer makes a Payment (one-to-one relationship).

Representation in ERD:

  • Relationships are typically represented as diamonds.
  • The relationship name (often a verb or verb phrase) is written inside the diamond.
  • Relationships are connected to entities via lines.

Types of Relationships:

  • One-to-One (1:1): A single instance of one entity is related to a single instance of another entity. For example, a Person may have only one Passport.
  • One-to-Many (1:M): One instance of an entity is related to multiple instances of another entity. For example, one Customer can place many Orders.
  • Many-to-Many (M:N): Multiple instances of one entity are related to multiple instances of another entity. For example, a Student can enroll in many Courses, and a Course can have many Students.

4. Cardinality

Cardinality defines the number of instances of one entity that can or must be associated with each instance of another entity in a relationship. It describes the nature of the relationship between two entities and can be one, many, or many-to-many.

  • One-to-One (1:1): Each instance of one entity is associated with exactly one instance of another entity.
  • One-to-Many (1:M): Each instance of one entity can be associated with multiple instances of another entity, but the reverse is not true.
  • Many-to-Many (M:N): Multiple instances of one entity can be associated with multiple instances of another entity.

Representation of Cardinality:

  • Cardinality is typically shown with symbols or annotations next to the relationship line. In Crow’s Foot Notation, a “crow’s foot” symbol represents “many,” while a straight line represents “one.”

ERD Notations and Symbols

1. Chen Notation (Classic ERD Notation)

Chen’s notation is the most classical and widely known notation for ERDs. It uses specific shapes for entities, relationships, and attributes.

  • Entity: Represented by a rectangle.
  • Attribute: Represented by an oval.
  • Relationship: Represented by a diamond.
  • Primary Key: Indicated by underlining the attribute.
  • Foreign Key: Represented by connecting an attribute from one entity to another entity.

2. Crow’s Foot Notation (Popular in Modern Database Design)

Crow’s Foot is one of the most widely used notations in modern ERD tools due to its simplicity and readability.

  • Entity: Represented by a rectangle (just like in Chen’s notation).
  • Attribute: Can be shown with ovals or simply written inside the entity box.
  • Relationship: Represented by a diamond or a straight line.
  • Cardinality: Use crow’s foot symbols to indicate “many” (three lines branching from a point) and a straight line for “one”.

3. UML Class Diagram Notation

While UML Class Diagrams are more object-oriented and used for class-based modeling, they also serve similar purposes to ERDs. UML uses classes (objects) and associations (relationships), and is most commonly used in software design, especially in object-oriented languages.


Creating an ERD

To create an ERD, follow these steps:

1. Identify the Entities

The first step is to identify the main entities that will be part of your system. These should represent the key concepts or objects within the system. For instance:

  • Customer
  • Order
  • Product
  • Payment

2. Identify Relationships Between Entities

Next, identify how entities are related. Determine whether the relationships are one-to-one, one-to-many, or many-to-many. For example:

  • A Customer can place many Orders (One-to-Many).
  • An Order can contain many Products (Many-to-Many).
  • A Payment is linked to exactly one Order (One-to-One).

3. Identify the Attributes

For each entity, identify the key attributes. For example:

  • Customer: Customer ID, Name, Email
  • Order: Order ID, Order Date, Customer ID
  • Product: Product ID, Name, Price
  • Payment: Payment ID, Amount, Payment Date, Order ID

4. Define Primary and Foreign Keys

Identify which attributes will act as primary keys (unique identifiers for entities) and which will be foreign keys (attributes that create relationships between entities).

5. Draw the ERD

Finally, draw the ERD using the following steps:

  • Place entities in rectangles.
  • Draw relationships (diamonds) between the entities and connect them.
  • Specify cardinalities by annotating the relationship lines.
  • Draw the attributes as ovals and connect them to their respective entities.

Best Practices for Designing ERDs

  1. Use Consistent Naming:
    • Use consistent naming conventions for entities, attributes, and relationships. The entity names should be singular nouns (e.g., Customer, Order, Product), while relationship names should be verbs or verb phrases (e.g., places, contains).
  2. Avoid Overcrowding:
    • Keep your ERD as simple as possible. If your system is complex, break the ERD into smaller, manageable sections or modules.
  3. Normalize the Data:
    • Apply database normalization principles (e.g., 1NF, 2NF, 3NF) to eliminate redundancy and ensure that the ERD reflects a logical structure for a relational database.
  4. Use Crow’s Foot Notation for Clarity:
    • For readability, use Crow’s Foot notation, which is more visually intuitive for indicating cardinality.
  5. Iterate and Validate:
    • The ERD should be reviewed and validated by stakeholders, including developers, domain experts, and business analysts, to ensure that it accurately represents the system and its requirements.

Suggested Questions

Basic Understanding & Conceptual Questions

  1. Define an Entity-Relationship Diagram (ERD). What is its primary purpose in database design?Answer: An Entity-Relationship Diagram (ERD) is a visual representation of the data structure in a database. It shows entities (things of significance), their attributes (properties), and the relationships between them. The primary purpose of an ERD is to model the data requirements for a system and demonstrate how entities relate to one another. It helps in understanding the system, organizing data, and designing relational databases efficiently.

  1. List and explain the basic components of an ERD.Answer: The basic components of an ERD include:
    • Entities: Represent things or objects within the system, such as Customer, Order, or Product. These are shown as rectangles.
    • Attributes: Characteristics of an entity, like Customer ID, Name, Email. These are represented by ovals.
    • Relationships: Represent the connections between entities. These are represented by diamonds, and their names usually describe the action or association (e.g., “places” for a customer placing an order).
    • Cardinality: Describes the number of instances of one entity that can be associated with instances of another entity, typically represented by symbols like “1” (one) and “N” (many).

  1. What is the difference between an entity and an attribute in an ERD? Provide examples for each.Answer:
    • Entity: An entity represents a real-world object or concept that is important in the system. Entities are shown as rectangles.
      • Example: Customer, Order, Product.
    • Attribute: An attribute is a property or characteristic of an entity. Attributes describe an entity’s data in detail and are represented as ovals.
      • Example: For the entity Customer, attributes could be Customer ID, Name, Email.

  1. Explain the different types of relationships in ERDs. Provide examples for each.Answer:
    • One-to-One (1:1): One instance of an entity is related to one instance of another entity.
      • Example: A Person has one Passport.
    • One-to-Many (1:M): One instance of an entity is related to many instances of another entity, but the reverse is not true.
      • Example: A Customer can place many Orders.
    • Many-to-Many (M:N): Many instances of one entity can be associated with many instances of another entity.
      • Example: A Student can enroll in many Courses, and a Course can have many Students.

  1. What is cardinality in the context of an ERD? Describe the different types of cardinality and provide an example for each.Answer: Cardinality defines the number of instances of one entity that can or must be associated with each instance of another entity in a relationship.
    • One-to-One (1:1): A single instance of one entity is associated with a single instance of another entity.
      • Example: A Person has exactly one Passport.
    • One-to-Many (1:M): A single instance of one entity can be associated with multiple instances of another entity.
      • Example: A Customer places many Orders.
    • Many-to-Many (M:N): Multiple instances of one entity can be associated with multiple instances of another entity.
      • Example: A Student enrolls in multiple Courses, and a Course can have multiple Students.

  1. What is the difference between a primary key and a foreign key in an ERD?Answer:
    • Primary Key: A primary key uniquely identifies each record within an entity. It is an attribute or set of attributes that uniquely identifies an entity.
      • Example: Customer ID for the Customer entity.
    • Foreign Key: A foreign key is an attribute in one entity that references the primary key in another entity, creating a relationship between the two entities.
      • Example: Customer ID in the Order entity is a foreign key referring to the primary key Customer ID in the Customer entity.

  1. Explain what is meant by a “many-to-many” relationship and how it is represented in an ERD.Answer: A many-to-many relationship occurs when multiple instances of one entity are associated with multiple instances of another entity. To represent a many-to-many relationship, a junction table (also known as an associative entity) is introduced to break the many-to-many relationship into two one-to-many relationships.
    • Example: A Student can enroll in many Courses, and each Course can have many Students. To represent this, a Student_Course table is introduced with foreign keys to both Student and Course.

  1. What is the purpose of using an ERD in database design? How does it help in understanding the data structure?Answer: The purpose of an ERD in database design is to provide a clear and visual representation of the database structure, helping to identify entities, their attributes, and relationships. It helps in understanding the overall data flow and organization, and is used to:
    • Ensure data integrity and consistency.
    • Identify potential issues in data relationships and cardinalities.
    • Serve as a blueprint for creating a database schema.
    • Facilitate communication between stakeholders (e.g., developers, business analysts) in understanding how the data will be structured.

Intermediate Design Questions

  1. Given the following requirements, draw an ERD:
    • Answer:
      • Entities:
        • Customer (Customer ID, Name, Email)
        • Order (Order ID, Order Date, Total Amount, Customer ID)
        • Product (Product ID, Product Name, Price)
        • Payment (Payment ID, Payment Date, Amount, Order ID)
      • Relationships:
        • A Customer places many Orders (One-to-Many).
        • An Order contains many Products (Many-to-Many, requires a junction table Order_Product).
        • An Order has one Payment (One-to-One).
      ERD would show entities in rectangles, relationships in diamonds, and the cardinalities (1:M, M:N, 1:1) marked accordingly.

  1. What is normalization, and why is it important in the context of ERD design? Explain 1NF, 2NF, and 3NF with examples.

Answer: Normalization is the process of organizing the attributes and relations of a database to minimize redundancy and dependency.

  • 1NF (First Normal Form): Each attribute contains only atomic values, meaning no repeating groups or arrays. Example: A Customer table with attributes Customer ID, Name, Phone Numbers where Phone Numbers is a list should be split into a separate table with a Phone Number ID and Customer ID.
  • 2NF (Second Normal Form): The database is in 1NF, and all non-key attributes are fully functionally dependent on the primary key. Example: In a table that stores both Customer and Order data, the Customer attributes should be in a separate table to avoid redundancy.
  • 3NF (Third Normal Form): The database is in 2NF, and all attributes are not transitively dependent on the primary key. Example: If a table stores Customer ID, Customer Name, and Customer State, and State Name, State Name should be moved to a separate State table.

  1. What are derived attributes in an ERD? Provide an example and explain how they are represented in the diagram.

Answer: Derived attributes are attributes whose values can be calculated or derived from other attributes. They are typically denoted by a dashed oval in ERDs.

  • Example: Age can be derived from the Date of Birth attribute in a Person entity. In an ERD, Age would be shown with a dashed oval.

  1. Explain how composite and multi-valued attributes are represented in an ERD. Provide examples.

Answer:

  • Composite Attributes: These are attributes that can be divided into smaller sub-parts. They are represented as ovals connected to an entity with ovals for each component.
    • Example: Full Name can be divided into First Name and Last Name.
  • Multi-valued Attributes: These are attributes that can have multiple values. They are shown as double ovals.
    • Example: A Customer can have multiple Phone Numbers.

  1. Draw an ERD using Crow’s Foot notation for the following scenario:

Answer: Entities:

  • Library: Library ID, Library Name
  • Book: Book ID, Title, Author, Genre
  • Author: Author ID, Name, Email
  • Member: Member ID, Name, Phone Number

Relationships:

  • A Library has many Books (One-to-Many).
  • A Book is written by one or more Authors (Many-to-Many, requires junction table Book_Author).
  • A Member can borrow many Books, and a Book can be borrowed by many Members (Many-to-Many, requires junction table Book_Borrow).
  1. You are designing a database for a company. Draw an ERD for the following scenario:
  • An Employee belongs to a Department and can work on multiple Projects.
  • A Project can involve multiple Employees.
  • An Employee can have many Skills.
  • Department has attributes: Dept ID, Dept Name.
  • Employee has attributes: Emp ID, Name, Email, Salary.
  • Project has attributes: Project ID, Project Name, Deadline.
  • Skill has attributes: Skill ID, Skill Name.

Answer:

  • Entities:
    • Employee (Emp ID, Name, Email, Salary)
    • Department (Dept ID, Dept Name)
    • Project (Project ID, Project Name, Deadline)
    • Skill (Skill ID, Skill Name)
  • Relationships:
    • An Employee works in one Department (1:M).
    • An Employee can work on multiple Projects, and a Project can have many Employees (M:N, requires junction table Employee_Project).
    • An Employee can have many Skills, and a Skill can belong to many Employees (M:N, requires junction table Employee_Skill).

The ERD would reflect the cardinality and junction tables for the many-to-many relationships.


  1. Explain the difference between a Chen notation and a Crow’s Foot notation in ERD design. Which one is more suitable for large-scale database design and why?

Answer:

  • Chen Notation: Uses rectangles for entities, ovals for attributes, diamonds for relationships, and lines to connect entities and relationships. This notation is more detailed, representing relationships clearly with cardinality specified near relationship lines.
  • Crow’s Foot Notation: Uses rectangles for entities, lines for relationships, and the “crow’s foot” symbol (three lines) at the “many” end of a relationship to indicate multiplicity. This notation is simpler, visually intuitive, and widely used for practical database design.

Suitability: Crow’s Foot notation is generally preferred for large-scale database design because it is less cluttered and easier to understand. It also focuses on the important elements of relationships, cardinality, and structure.


  1. Describe the process of converting an ERD into a relational schema. Provide an example using a simple ERD.

Answer: The process of converting an ERD into a relational schema involves translating the entities, relationships, and attributes in the ERD into tables, columns, and keys for a relational database. The steps are as follows:

  1. Entities become tables, with each entity’s attributes becoming the table’s columns.
  2. Primary Keys are assigned to uniquely identify rows in each table.
  3. Relationships are translated:
    • One-to-One (1:1): Foreign key is added to either of the related tables.
    • One-to-Many (1:M): The primary key of the “one” side is added as a foreign key in the “many” side.
    • Many-to-Many (M:N): A junction table is created with foreign keys from both related tables.

Example: Given an ERD with entities Customer and Order:

  • Customer table: Customer_ID (PK), Name, Email
  • Order table: Order_ID (PK), Order_Date, Customer_ID (FK)

In this case, Customer_ID in the Order table is a foreign key referring to the primary key in the Customer table.


  1. What is the role of a foreign key in an ERD? How does it maintain referential integrity between related entities?

Answer: A foreign key is an attribute in one table that refers to the primary key of another table. It creates a relationship between the two tables, ensuring that data is consistent and valid. The foreign key enforces referential integrity, meaning:

  • The value in the foreign key column must match a value in the primary key column of the referenced table (or be null if allowed).
  • It ensures that there are no “orphan” records in the dependent table that do not have a matching record in the referenced table.

Example: In an Order table, the Customer_ID foreign key points to the Customer_ID primary key in the Customer table. This ensures that an order cannot exist without a valid customer.


  1. How would you modify an ERD to handle a scenario where a Customer can have multiple shipping addresses, but each shipping address is associated with only one Customer?

Answer: In this scenario, you would add an entity for ShippingAddress and create a one-to-many relationship between Customer and ShippingAddress. Each ShippingAddress would have a foreign key referring to Customer_ID.

Entities:

  • Customer (Customer_ID, Name, Email)
  • ShippingAddress (Address_ID, Street, City, State, Zip_Code, Customer_ID)

Relationship:

  • A Customer can have many ShippingAddresses, but a ShippingAddress belongs to one Customer (1:M).

Case Study & Practical Application

  1. Given a scenario where a company wants to track employee information, projects, and performance reviews, design an ERD with the following requirements:
  • An Employee works in one Department.
  • An Employee is assigned multiple Projects.
  • An Employee receives many Performance Reviews.
  • Each Project can involve multiple Employees.
  • Performance Review has attributes: Review ID, Date, Rating.

Answer:

  • Entities:
    • Employee (Emp_ID, Name, Email, Department_ID)
    • Department (Dept_ID, Dept_Name)
    • Project (Project_ID, Project_Name, Start_Date, End_Date)
    • PerformanceReview (Review_ID, Review_Date, Rating, Emp_ID)
  • Relationships:
    • An Employee works in one Department (1:M).
    • An Employee works on multiple Projects, and a Project can have many Employees (M:N, junction table Employee_Project).
    • An Employee can have multiple PerformanceReviews, and each Review is for one Employee (1:M).

  1. Create an ERD for a Hospital Management System that includes entities like Doctor, Patient, Appointment, Prescription, and Treatment. Indicate the relationships between these entities and explain the cardinality for each relationship.

Answer:

  • Entities:
    • Doctor (Doctor_ID, Name, Specialization)
    • Patient (Patient_ID, Name, DOB, Phone)
    • Appointment (Appointment_ID, Appointment_Date, Doctor_ID, Patient_ID)
    • Prescription (Prescription_ID, Date, Patient_ID, Doctor_ID)
    • Treatment (Treatment_ID, Treatment_Name, Treatment_Date, Patient_ID)
  • Relationships:
    • A Doctor can have many Appointments (1:M).
    • A Patient can have many Appointments (1:M).
    • A Patient can have many Prescriptions (1:M).
    • A Doctor can write many Prescriptions (1:M).
    • A Patient can receive multiple Treatments (1:M).

  1. In an ERD for a hotel reservation system, describe how you would represent a many-to-many relationship between Guest and Room (a guest can book multiple rooms, and each room can be booked by many guests). How would you structure this in the ERD?

Answer: In this case, you would create a junction table called Guest_Room to represent the many-to-many relationship between Guest and Room. The junction table would contain foreign keys referring to both Guest_ID and Room_ID.

Entities:

  • Guest (Guest_ID, Name, Email)
  • Room (Room_ID, Room_Number, Room_Type)
  • Guest_Room (Guest_ID, Room_ID, Booking_Date)

The Guest_Room table would act as the many-to-many relationship table, where each guest can book many rooms, and each room can be booked by many guests.


  1. Consider an online education system with entities like Course, Student, Instructor, Enrollment, and Assignment. Draw the ERD and explain how you would handle many-to-many relationships between Student and Course, and between Instructor and Course.

Answer:

  • Entities:
    • Course (Course_ID, Course_Name, Credits)
    • Student (Student_ID, Name, Email)
    • Instructor (Instructor_ID, Name, Email)
    • Enrollment (Enrollment_ID, Student_ID, Course_ID)
    • Assignment (Assignment_ID, Title, Course_ID)
  • Relationships:
    • A Student can enroll in multiple Courses, and a Course can have many Students (M:N, junction table Enrollment).
    • An Instructor teaches many Courses, and a Course can be taught by many Instructors (M:N).

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top