Skip to main content

ER Model

The Entity-Relationship (ER) model is a conceptual data model used to describe the structure of a database at a high level, independent of any specific database system. It was introduced by Peter Chen in 1976.

Core Concepts

Entities

An entity is a real-world object or concept that is distinguishable from other objects. Entities of the same kind are grouped into entity types (e.g., Customer, Product, Order). A single occurrence is called an entity instance.

Attributes

Attributes describe the properties of an entity type.

TypeDescriptionExample
SimpleAtomic, indivisible valueFirstName, Age
CompositeMade up of sub-attributesAddress = (Street, City, ZIP)
MultivaluedCan hold multiple valuesPhoneNumbers
DerivedComputed from another attributeAge derived from BirthDate

The key attribute (primary key) uniquely identifies each entity instance, e.g., CustomerID.

Relationships

A relationship describes an association between two or more entity types. Like entities, relationships are grouped into relationship types (e.g., a Customer places an Order). Relationships can also have their own attributes (e.g., a WorksFor relationship might carry a StartDate).

Cardinality

Cardinality defines how many instances of one entity can be associated with instances of another.

TypeDescriptionExample
1:1One instance relates to exactly one otherOne person has one passport
1:NOne instance relates to many othersOne customer places many orders
N:MMany instances relate to many othersStudents enroll in multiple courses; courses have multiple students

Participation further specifies whether every entity instance must take part in a relationship:

  • Total participation (mandatory): Every instance must be in at least one relationship, e.g., every order must belong to a customer.
  • Partial participation (optional): Some instances may not participate, e.g., not every customer has placed an order.

Weak Entities

A weak entity cannot be uniquely identified by its own attributes alone. It depends on a strong (owner) entity for its identity.

  • The weak entity has a partial key (discriminator) that is unique only within the context of its owner.
  • The relationship connecting a weak entity to its owner is called an identifying relationship.

Example: OrderItem is a weak entity. Its partial key LineNumber is only unique within a specific Order. The full identity is (OrderID, LineNumber).

Example: Order Management

The following example shows a Customer who places Orders, each consisting of one or more OrderItems. OrderItem is a weak entity, since a LineNumber only makes sense in the context of a specific order.

┌──────────────────┐ ┌──────────────────┐
│ Customer │ │ Order │
├──────────────────┤ ├──────────────────┤
│ CustomerID (PK) │─── 1 ── places ── N ─│ OrderID (PK) │
│ Name │ │ OrderDate │
│ Email │ └────────┬─────────┘
└──────────────────┘ │ 1

contains
(identifying)

│ 1..*
╔════════╧═════════╗
║ OrderItem ║
╠══════════════════╣
║ ~LineNumber ║
║ Quantity ║
╚══════════════════╝

Mapping to Relational Tables

ER conceptRelational mapping
Entity typeTable
AttributeColumn
Key attributePrimary key
1:N relationshipForeign key on the N-side table
N:M relationshipJunction table with foreign keys to both entity tables
Weak entityTable with composite primary key (owner key + partial key)