ERD Practice Problems: Build Confidence with Realistic Scenarios

Designing a robust database requires more than just understanding syntax. It demands a clear mental model of how data interacts within a real-world system. Entity Relationship Diagrams (ERDs) serve as the blueprint for this structure. Without practice, the theoretical concepts of normalization, cardinality, and foreign keys remain abstract. To truly grasp database modeling, you must engage with practical problems that mimic actual business logic.

This guide focuses on applying ERD principles through specific, realistic scenarios. By working through these examples, you will strengthen your ability to identify entities, define relationships, and avoid common structural errors. The goal is to develop a reliable workflow for translating complex requirements into clean, efficient data models.

Understanding the Core Components 🧱

Before diving into scenarios, it is essential to review the building blocks of an ERD. A strong foundation ensures that when you face complex requirements, you do not have to relearn the basics.

1. Entities and Attributes

  • Entities: These represent distinct objects or concepts within your system. Examples include Customer, Product, or Employee.
  • Attributes: These describe the properties of an entity. For a Customer, attributes might be CustomerID, Name, and EmailAddress.
  • Primary Keys: Every entity requires a unique identifier to distinguish one record from another.

2. Relationships and Cardinality

The connection between entities defines the integrity of your data. Cardinality specifies the number of instances of one entity that relate to another.

Cardinality Type Description Example
One-to-One (1:1) One instance relates to exactly one instance of another entity. One Employee has one ID Card.
One-to-Many (1:N) One instance relates to many instances of another entity. One Department has many Employees.
Many-to-Many (M:N) Many instances relate to many instances of another entity. Many Students enroll in many Courses.

Scenario 1: E-Commerce Platform 🛒

Online retail systems involve complex transactions, inventory management, and user accounts. This scenario tests your ability to handle junction tables and status tracking.

Requirements Analysis

  • A customer can place multiple orders over time.
  • A single order can contain multiple products.
  • A product can be part of many different orders.
  • Each order must track a specific status (e.g., Pending, Shipped).
  • Products belong to specific categories.

Modeling Steps

  1. Identify Entities: Customer, Order, Product, Category.
  2. Define Attributes:
    • Customer: CustomerID, FirstName, LastName, Email.
    • Order: OrderID, OrderDate, Status, ShippingAddress.
    • Product: ProductID, Name, Price, StockQuantity.
    • Category: CategoryID, CategoryName.
  3. Determine Relationships:
    • Customer to Order: One-to-Many. One customer generates many orders.
    • Order to Product: Many-to-Many. An order holds many products, and a product is in many orders. This requires a junction table.
    • Product to Category: Many-to-One. Many products belong to one category.

Refining the Design

For the Many-to-Many relationship between Order and Product, you must create a junction table often called OrderItems. This table breaks the direct link and allows you to store specific data about the transaction line, such as Quantity and UnitPriceAtTimeOfSale.

  • OrderItems Attributes: OrderItemID, OrderID (Foreign Key), ProductID (Foreign Key), Quantity, UnitPrice.
  • Normalization Check: Ensure UnitPrice is stored here and not in the Product table, as prices change over time.

Scenario 2: Hospital Management System 🏥

Healthcare databases require high accuracy due to the critical nature of the data. This scenario emphasizes strict data integrity and hierarchical relationships.

Requirements Analysis

  • Doctors specialize in specific departments.
  • Patients visit doctors for appointments.
  • A doctor can have multiple patients, and a patient can see multiple doctors.
  • Prescriptions are issued during appointments.
  • Each patient has a unique medical record.

Modeling Steps

  1. Identify Entities: Doctor, Patient, Appointment, Prescription, Department.
  2. Define Attributes:
    • Doctor: DoctorID, Name, Specialization, LicenseNumber.
    • Department: DepartmentID, DepartmentName, HeadDoctorID.
    • Appointment: AppointmentID, DateTime, DiagnosisNotes.
    • Prescription: PrescriptionID, MedicationName, Dosage, Duration.
  3. Determine Relationships:
    • Department to Doctor: One-to-Many. A department employs many doctors.
    • Doctor to Appointment: One-to-Many. A doctor conducts many appointments.
    • Patient to Appointment: One-to-Many. A patient attends many appointments.
    • Appointment to Prescription: One-to-Many. One appointment can result in multiple prescriptions.

Handling Complex Constraints

In this scenario, data integrity is paramount. You must ensure that a prescription cannot exist without a linked appointment. This is enforced through foreign key constraints.

  • Self-Referencing Relationship: A Doctor entity might need to link to a Head Doctor within the same table. This is a One-to-One relationship where the HeadDoctorID references the DoctorID.
  • Temporal Data: Appointments have specific dates. Ensure the DateTime field is stored in a standard format to allow for scheduling queries.

Scenario 3: University Student Portal 🎓

Academic systems involve heavy Many-to-Many relationships and conditional logic. This scenario focuses on managing enrollments and prerequisites.

Requirements Analysis

  • Students enroll in multiple courses.
  • Each course has multiple instructors.
  • A course can be offered in multiple semesters.
  • Some courses have prerequisites.
  • Grades are assigned per student per course.

Modeling Steps

  1. Identify Entities: Student, Course, Instructor, Semester, Enrollment.
  2. Define Attributes:
    • Student: StudentID, GPA, Major.
    • Course: CourseCode, Title, Credits.
    • Instructor: InstructorID, Name, Title.
    • Enrollment: EnrollmentID, Grade, SemesterYear.
  3. Determine Relationships:
    • Student to Course: Many-to-Many. Managed via the Enrollment junction table.
    • Course to Instructor: Many-to-Many. A course can be taught by multiple instructors over time.
    • Course to Prerequisite: Self-referencing. A course lists another course as a prerequisite.

Addressing the Prerequisite Logic

The prerequisite requirement creates a recursive relationship within the Course entity. You need a column in the Course table, say PrerequisiteCourseID, which references the CourseID of another row in the same table.

  • Implementation: This allows a Math 101 course to link to a Math 100 course.
  • Validation: The system must prevent a course from being its own prerequisite to avoid circular logic errors.

Common Pitfalls in ERD Design ⚠️

Even experienced designers make mistakes. Reviewing common errors helps you refine your models before implementation.

1. Redundant Data

Storing the same information in multiple places increases the risk of inconsistency. For example, storing a customer’s address in the Order table is acceptable for shipping purposes, but the Customer table should remain the source of truth for their permanent address.

  • Check: Ask if changing an attribute in one table requires updates in others.
  • Fix: Normalize the data to Third Normal Form (3NF) where possible.

2. Ambiguous Relationships

Sometimes it is unclear if a relationship is mandatory or optional. In a Customer to Order relationship, a customer exists before they place an order. However, an order must always belong to a customer.

Concept Meaning
Optional Relationship The entity on this side does not require a link to the other entity.
Mandatory Relationship The entity on this side must have a link to the other entity.

3. Ignoring Data Types

Choosing the wrong data type can lead to storage inefficiencies or calculation errors. For instance, using an Integer for a Price field without decimals will result in lost currency precision.

  • Best Practice: Use Decimal types for currency and Date/Time types for scheduling.
  • Constraint: Define maximum lengths for text fields to prevent database bloat.

Step-by-Step Modeling Workflow 📝

Follow this structured approach to ensure consistency across all your practice problems.

  1. Gather Requirements: List every noun (Entity) and verb (Relationship) found in the problem description.
  2. Draft the Initial Diagram: Place entities and draw lines to represent connections. Do not worry about perfection yet.
  3. Assign Keys: Identify the Primary Key for every entity and the Foreign Keys for every relationship.
  4. Refine Cardinality: Verify the 1:1, 1:N, and M:N relationships against the business rules.
  5. Add Attributes: Flesh out each entity with necessary fields. Remove any that are derived from other fields.
  6. Review for Normalization: Ensure no transitive dependencies exist (e.g., if A determines B, and B determines C, then A should not determine C directly).
  7. Final Validation: Walk through a data entry scenario to see if the model supports it.

Self-Assessment Checklist ✅

Before finalizing your ERD, run through this checklist to ensure quality.

  • Uniqueness: Does every table have a Primary Key?
  • Consistency: Are data types consistent across related tables?
  • Completeness: Can you insert all required data without violating constraints?
  • Clarity: Are entity and attribute names descriptive and standardized?
  • Scalability: Will the design hold up if the volume of data increases tenfold?
  • Constraints: Are null constraints applied correctly where data is mandatory?

Advanced Considerations 🚀

As you gain confidence, you can explore more advanced modeling techniques.

1. Weak Entities

A weak entity depends on another entity for its existence. For example, an OrderLine cannot exist without an Order. Its primary key is usually a combination of its own partial key and the owner’s primary key.

2. Inheritance

Sometimes entities share common attributes. In a Employee system, FullTime and PartTime employees share an ID and Name but differ in benefits. You can model this using a superclass and subclass structure.

3. Temporal Tables

Some data changes over time. A ProductPrice changes weekly. You might need to store the history of price changes rather than just the current value. This requires adding effective start and end dates to your attributes.

Final Considerations for Practice 💡

Building confidence in ERD design is a gradual process. It involves continuous refinement and critical thinking about how data flows through a system. By working through realistic scenarios like E-Commerce, Healthcare, and Education, you expose yourself to various structural challenges.

Remember that there is rarely a single “perfect” model. Different applications may prioritize different aspects, such as read speed versus write speed. The key is to understand the trade-offs involved in your design choices.

Continue to practice with new requirements. Try to model a library system, a hotel reservation system, or a social media network. Each domain presents unique constraints and relationship patterns. The more you practice, the more intuitive the process becomes.

Key Takeaways

  • Entities are the foundation: Define them clearly before linking them.
  • Cardinality matters: Ensure the relationship types match business rules.
  • Normalization reduces risk: Avoid redundancy to maintain data integrity.
  • Review regularly: Always validate your design against new requirements.

With dedication and structured practice, you will develop the skills needed to design reliable, scalable database systems. Focus on the logic behind the connections, and the technical implementation will follow naturally.