How to Draw an ER Diagram: Entities, Relationships and Cardinality

The practical purpose of an ER diagram is to settle relationships before the schema exists. Discovering afterwards that an order can have several shipping addresses is no longer a diagram change — it is a data migration. Half an hour drawing saves weeks of migration later.

Cutting entities: one entity, one table

An entity is something that exists independently, has its own identity, and gets queried on its own: user, order, product, shipping address. The test is an independent lifecycle — an order is created and queried on its own, so it is an entity; payment status is not an entity, it is an attribute of the order.

  • Name entities with singular nouns that map to future table names
  • Every entity must have an identifiable key, usually a surrogate or business ID
  • Show only key fields; listing every column makes the diagram unmanageable
  • An "attribute" that needs independent querying or updating is usually a missing entity

Cardinality: be explicit about one and many

Cardinality describes how many: one-to-one, one-to-many, many-to-many. Of the three, many-to-many demands action, because a relational database cannot express it directly — a junction table is mandatory. Leave it unmarked on the diagram and someone will take the shortcut of stuffing several values into one column.

  • One-to-many: the foreign key lives on the many side, marked N
  • Many-to-many: split out a junction entity with one-to-many on both sides
  • One-to-one: often optional; splitting is usually driven by column count or access rights
  • Mark optional versus mandatory — it decides whether the foreign key may be null

Three recurring design defects

When reviewing someone else’s ER diagram, look for these three first — the hit rate is high. All of them are invisible on the diagram and expensive after launch, which is exactly why they are worth catching in review.

  1. Redundant storage: the same data held in two entities will drift out of sync; keep one source of truth
  2. Missing junction table: connecting many-to-many directly makes it impossible to record relationship attributes such as join date or role
  3. Entities that are too coarse: objects that should stand alone get folded into columns, and later need a schema change just to be queried

Notation: boxes, lines, labels

The conventional notation is a rectangle per entity with fields listed inside and keys marked, plus connecting lines labelled with cardinality at each end. If your tool has no dedicated ER template, rectangles and connectors are entirely sufficient — clarity of labels matters more than formal symbol compliance.

  • List fields on separate lines inside the box with keys first and marked
  • Use straight lines for relationships and write cardinality at both ends
  • When a relationship carries attributes, add a small box on the line
  • Keep lines short and uncrossed; place frequently joined entities near each other

From ER diagram to schema

Converting an ER diagram into tables is largely mechanical: one table per entity, the foreign key on the many side, a junction table with a composite unique index for many-to-many. That it converts mechanically is a good sign — if it requires heavy improvisation, the diagram is not finished.

  • Give junction tables a composite unique constraint to prevent duplicate links
  • Identify indexes for common query paths and mark them on the diagram
  • Decide the delete policy — cascade or retain history — before defining foreign keys
  • Reconcile the diagram against the real schema periodically so they do not diverge

Frequently asked questions

How does an ER diagram relate to the actual schema?
The ER diagram is the design-stage abstraction and the schema is the implementation; they normally correspond one-to-one but need not. The diagram shows key fields and relationships while the schema carries every column, index, and constraint. Name entities identically to their tables so the two can be compared easily.
Is a junction table always required for many-to-many?
In a relational database, yes. Storing multiple IDs in one column makes foreign keys impossible, makes querying by relationship inefficient, and leaves nowhere to record attributes of the relationship itself such as creation date or role. A junction table is both simpler and more extensible.
Should an ER diagram specify column types?
For design review it is usually unnecessary — field names and key status are enough. Handle types and indexing in a separate implementation note; separating the two kinds of information keeps design review fast.
What about tables with a very large number of columns?
First ask whether those columns share a lifecycle and access frequency. If a subset is rarely read, or updates on a different cadence, split it into a one-to-one companion table. The criterion is access pattern, not column count by itself.

Related guides