Skip to main content

Entity Relationship Model (ER Model)

The Entity–Relationship (ER) model is a fundamental concept in database design used to represent real-world systems in a structured way. It models data as a collection of entities and the relationships between them.

Basic Elements​

1. Entity​

An entity is a real-world object or concept that is distinguishable from all other objects. It can be physical (a house, an employee) or conceptual (a loan, a transaction).

  • Entity Type: A collection of entities that share the same attributes.
  • Entity Set: All instances of a particular entity type in the database at a specific point in time.

Strong vs Weak Entity​

  • Strong Entity: Its existence is independent of other entities.
  • Weak Entity: Its existence depends on a parent (strong) entity. They don't have their own primary key.

2. Attributes​

Attributes are descriptive properties possessed by each member of an entity set.

Types of attributes:

  • Simple (Atomic): Indivisible (e.g., age).
  • Composite: Can be divided into smaller sub-parts (e.g., Address -> Street, City, Zip).
  • Single-valued vs Multi-valued: Multi-valued attributes hold multiple values (e.g., Phone Numbers).
  • Derived: Calculated from other stored attributes (e.g., calculating Age from Date of Birth).

3. Relationship​

A relationship defines an association among several entities. For example, a Student enrolled_in a Course.

Mapping Constraints (Cardinality)​

Determines how many entities of one kind can be associated with another.

  • One to One (1:1)
  • One to Many (1:N)
  • Many to One (N:1)
  • Many to Many (M:N)

Keys in ER Model​

Keys uniquely identify rows and relationships.

  • Super Key: Any set of attributes that can uniquely identify an entity.
  • Candidate Key: A minimal super key.
  • Primary Key: A chosen candidate key by the DBA. It cannot be null.

ER Diagram Representation​

We can visually model databases using ER diagrams. Modern ER diagrams are often represented conceptually or physically using tools like Mermaid.

A simple ER diagram showing 1-to-many relationships using Crow's foot notation.