ER Diagrams
Imagine designing the database for a university before writing a single line of SQL. Students enroll in courses. Courses are taught by instructors. Instructors belong to departments. Every one of these facts must be captured correctly before any table is created. Getting the structure wrong at this stage is expensive. A missing cardinality constraint or an ambiguous relationship can silently corrupt data for years. The ER diagram is the tool that lets a designer draw this structure on paper (or a whiteboard). It allows reasoning about the structure before committing to a schema. An ER diagram is the graphical notation for Entity-Relationship Modeling. It turns the abstract notions of entities, relationships, and attributes into boxes, diamonds, ovals, and lines. A team can review these together. It is a communication device as much as a design device. A client who has never heard of a foreign key can still look at an ER diagram. They can confirm "yes, one department has many instructors." They can also confirm "no, a student can take many courses, not just one." That shared vocabulary between database designers and domain experts is the diagram's real power. This article treats the ER diagram as a precise notation, not just a sketch. Every shape has a defined meaning. Every line carries a cardinality constraint. Every diagram can be mechanically checked for consistency. We cover the classical Chen notation (entity sets, relationship sets, attributes). We also cover the more compact "crow's foot" style used in modern tools. We show how to encode one-to-one, one-to-many, and many-to-many relationships. We also show how to express total versus partial participation. By the end, you will be able to read and draw ER diagrams for real-world scenarios. You will be able to spot the classic notational traps (which cardinality symbol goes where). You will understand why the diagram is drawn the way it is. This is because it must unambiguously determine the relational schema that follows. That translation step is covered by Mapping ER to Relations. But the diagram itself is the contract that translation must honor.
- ER diagrams graphically represent entity sets (rectangles), relationship sets (diamonds), and attributes (ovals).
- Lines connecting entities to relationships carry cardinality constraints: 1:1, 1:N, N:1, or M:N.
- Participation constraints (total vs. partial) specify whether every entity instance must participate in a relationship.
- Two dominant notations exist: Chen's original diamond notation and the widely-used crow's foot notation.
- Weak entity sets, derived attributes, and multivalued attributes each have dedicated symbols.
- A well-formed ER diagram fully determines the relational schema, keys, and constraints that follow from it.
An ER diagram is a precise, checkable picture of entities, relationships, and cardinality constraints — not a free-form sketch.
The idea
An ER diagram is the standard graphical notation for an entity-relationship model. It represents three core constructs. An entity set — a collection of entities of the same type, such as all `Student` records — is drawn as a rectangle. A relationship set — an association among entities from one or more entity sets, such as `Advises` linking `Instructor` to `Student` — is drawn as a diamond. An attribute — a property of an entity or relationship, such as `name` or `GPA` — is drawn as an oval connected to its owning rectangle or diamond by a line. Beyond these basic shapes, the notation must express constraints that are otherwise invisible in a plain graph. A cardinality constraint on the edge between an entity set and a relationship set states how many relationship instances an entity can participate in: one-to-one (1:1), one-to-many (1:N), many-to-one (N:1), or many-to-many (M:N). A participation constraint states whether every entity in the set must appear in at least one relationship instance (total participation, drawn as a double line) or whether participation is optional (partial participation, a single line). Together, cardinality and participation constraints are what make an ER diagram a specification, not just an illustration — they are exactly the facts needed to decide primary keys, foreign keys, and nullability when the diagram is later mapped to relations. Two special constructs complete the notation. A weak entity set is one that has no key attributes of its own and depends existentially on an identifying (or owner) entity set through a special identifying relationship; it is drawn with a double-outlined rectangle, and its identifying relationship gets a double-outlined diamond. A multivalued attribute (an attribute that can hold several values for one entity, like `phone_number`) is drawn with a double oval, and a derived attribute (computable from other attributes, like `age` from `date_of_birth`) is drawn with a dashed oval. Composite attributes (like `address` decomposing into `street`, `city`, `zip`) are drawn as an oval with sub-ovals hanging off it.
How it works
Building an ER diagram is a systematic process: identify entity sets, identify relationship sets among them, attach attributes, then annotate every edge with cardinality and participation constraints. The steps below describe the design procedure and, separately, the algorithmic check for whether a completed diagram is well-formed.
Step 1 — Identify entity sets. Scan the requirements for nouns that denote things with independent existence and enough attributes to be worth tracking as a group: `Student`, `Course`, `Department`, `Instructor`.
Step 2 — Identify key attributes. For each strong entity set, choose one or more attributes (or a combination) that uniquely identify each entity — the primary key, underlined in the diagram. `Student.ID`, `Course.course_id`.
Step 3 — Identify relationship sets. Scan for verbs connecting entity sets: a student takes a course, an instructor teaches a course, a department offers a course. Each becomes a diamond connected to the entity sets it relates.
Step 4 — Attach descriptive attributes. Attributes that belong to the association itself, not to either entity alone — such as the `grade` a student receives in a specific course — attach to the relationship diamond, not to either entity.
Step 5 — Determine cardinality for each entity–relationship edge. Ask: "for one fixed entity on this side, how many entities on the other side can it be associated with?" This determines whether the edge is 1, or many (N/M).
Step 6 — Determine participation for each edge. Ask: "must every entity in this set appear in this relationship, or is it optional?" Total participation forces a double line; partial gets a single line.
Step 7 — Handle weak entity sets. If an entity set has no natural key of its own (e.g., a `Room` within a `Building`, identified only in conjunction with its building), mark it and its identifying relationship with double borders, and underline its discriminator (partial key) with a dashed line. The algorithm below formalizes the validation pass — checking that a proposed diagram is internally consistent — which a CASE tool or a careful designer runs after steps 1–7. ``` ALGORITHM ValidateERDiagram(EntitySets, RelationshipSets, Attributes, Constraints) // EntitySets: set of entity set descriptors, each with a set of attributes // RelationshipSets: set of relationship descriptors, each connecting >=2 entity sets // Constraints: cardinality and participation labels per (entity set, relationship) edge errors <- empty list // 1. Every strong entity set must have a declared key for each E in EntitySets: if E is not weak and E.keyAttributes is empty: errors.append("Strong entity set " + E.name + " has no key") // 2. Every weak entity set must have exactly one identifying relationship // and its owner must have total participation in it for each E in EntitySets where E.isWeak: idRels <- { R in RelationshipSets : R.isIdentifying and E in R.connectedEntities } if size(idRels) != 1: errors.append("Weak entity set " + E.name + " must have exactly one identifying relationship") else: R <- the element of idRels owner <- the other entity set connected by R if Constraints[owner, R].participation != TOTAL: errors.append("Owner of weak entity " + E.name + " must have total participation") if E.discriminator is empty: errors.append("Weak entity set " + E.name + " has no discriminator") // 3. Every relationship set edge must have a defined cardinality and participation for each R in RelationshipSets: for each E in R.connectedEntities: if Constraints[E, R] is undefined: errors.append("Missing cardinality/participation for " + E.name + "-" + R.name) // 4. No entity set may be isolated (no relationships at all), unless declared standalone for each E in EntitySets: if E has no relationships and not E.isStandaloneAllowed: errors.append("Entity set " + E.name + " is isolated") // 5. Attribute placement check: shared/associative attributes // must attach to the relationship, not duplicated on both entities for each R in RelationshipSets where R.cardinality == MANY_TO_MANY: for each attr in R.descriptiveAttributes: if attr appears in any connected entity set's Attributes: errors.append("Attribute " + attr + " duplicated between entity and M:N relationship") return errors ``` Running this over a candidate diagram takes time proportional to the number of entity sets, relationship sets, and attributes — there is no search or backtracking, only a linear scan of each construct and its declared constraints.
Complexity & correctness
Space complexity. A diagram with entity sets, relationship sets, and total attributes occupies drawing elements, since each entity set, relationship set, and attribute contributes a constant number of shapes and each connecting edge is drawn once per (entity set, relationship set) incidence. If a relationship connects entity sets (a -ary relationship, ), it contributes edges, so total edges are bounded by in the worst case, but in essentially every practical schema relationships are binary or ternary, so this is effectively .
Validation time. The `ValidateERDiagram` procedure above touches each entity set, each relationship set, and each attribute a constant number of times per check, and there are a constant number of checks (key existence, weak-entity well-formedness, constraint completeness, isolation, attribute duplication). Hence validation runs in time — linear in the size of the diagram, with no combinatorial blow-up, because well-formedness is a local property: it only requires inspecting each construct and its immediate neighbors, never reasoning about paths or cycles in the diagram.
Correctness argument. "Correctness" for an ER diagram means: the diagram is a faithful and unambiguous encoding of the requirements, and it contains enough information to derive a relational schema mechanically. Three invariants must hold for this to be true, and the validation algorithm checks exactly these: 1. Key invariant. Every strong entity set must have a designated key, because the eventual relational table for that entity set needs a primary key; without it, step 3 of Mapping ER to Relations (choosing the primary key of the entity's table) is undefined. This is why check 1 rejects keyless strong entities. 2. Weak-entity invariant. A weak entity set's rows cannot be uniquely identified without its owner, so its identifying relationship must exist and be exactly one, and the owner's participation in it must be total — every weak entity instance must have an owner, or it corresponds to no real-world fact. Formally, if is a weak entity set with discriminator and owner with key , the composite must be a candidate key for 's eventual table; this is only guaranteed if every -instance is linked to exactly one -instance, which is precisely total participation of combined with a single identifying relationship (many-to-one, weak side to owner). 3. Constraint-completeness invariant. Every edge between an entity set and a relationship set must carry a cardinality and participation label, because the mapping algorithm branches on these labels (1:1 relationships may merge into one table; M:N relationships always need a separate table). An unlabeled edge is an ambiguous specification — the diagram would admit multiple, non-equivalent relational schemas, defeating its purpose as a contract.
Honesty about tradeoffs. ER diagrams excel at capturing structural constraints (existence, cardinality, keys) but are notation-poor for capturing complex business rules ("a student cannot enroll in two sections that meet at the same time"), which must be pushed into constraints, triggers, or application logic later. Chen notation (diamonds) is precise and pedagogically clean but visually heavy for large schemas; crow's-foot notation is compact and closer to what industrial tools (like ER/Studio or MySQL Workbench) render, but it compresses cardinality and participation into a single symbol at the edge's end, which is easy to misread. Neither notation prevents a designer from modeling the same real-world fact in structurally different but equally "valid" ways — e.g., representing `grade` as a relationship attribute versus promoting `Enrollment` to its own entity set — so ER diagrams constrain consistency, not uniqueness, of design.
Worked example
Consider modeling a small library system with these requirements: "Each book has an ISBN, title, and one or more authors. A library branch has a name and address. Each physical copy of a book belongs to exactly one branch and has a copy number unique within that branch. A member, identified by member ID, may borrow copies; we record the borrow date for each borrowing." We trace the design steps against this text.
| Step | Decision | Reasoning |
|---|---|---|
| 1. Entity sets | `Book`, `Branch`, `Copy`, `Member` | Nouns with independent existence and multiple attributes |
| 2. Keys | `Book.ISBN`; `Branch.name`; `Member.member_id`; `Copy` — no natural key | A copy is only unique within a branch (copy number repeats across branches) |
| 3. Weak entity | `Copy` is weak, identified by (`Branch`, `copy_number`) | No standalone key exists for `Copy` |
| 4. Relationship: `Has_Copy` | Connects `Book`–`Copy`, identifying? No — `Book` doesn't identify `Copy`, `Branch` does | So the identifying relationship is `Belongs_To` (`Branch`–`Copy`), and `Has_Copy` is an ordinary 1:N relationship (`Book`–`Copy`) |
| 5. Relationship: `Belongs_To` | `Branch`(1) — `Copy`(N), identifying, total participation on `Copy` side | Every copy must belong to exactly one branch; a branch can have zero or many copies |
| 6. Relationship: `Borrows` | `Member`(M) — `Copy`(N), descriptive attribute `borrow_date` on the relationship | A member may borrow many copies over time; a copy may (over its lifetime) be borrowed by many members, but not simultaneously — modeled here as a historical M:N |
| 7. Multivalued attribute | `Book.author` is multivalued (double oval) | "One or more authors" per book |
| 8. Participation | `Copy` has total participation in `Belongs_To` (every copy has a branch) and total participation in `Has_Copy` (every copy is a copy of some book); `Member` has partial participation in `Borrows` (a member need not currently be borrowing anything) |
Running `ValidateERDiagram` conceptually on this design:
- Check 1 (strong entity keys): `Book`, `Branch`, `Member` all have keys — pass. `Copy` is weak, so exempt — correctly skipped.
- Check 2 (weak entity): `Copy` has exactly one identifying relationship (`Belongs_To`), owner `Branch` has total participation in it, and discriminator `copy_number` is declared — pass.
- Check 3 (constraint completeness): every edge (`Book`–`Has_Copy`, `Copy`–`Has_Copy`, `Branch`–`Belongs_To`, `Copy`–`Belongs_To`, `Member`–`Borrows`, `Copy`–`Borrows`) has a declared cardinality/participation — pass.
- Check 4 (isolation): no entity set stands alone — pass.
- Check 5 (attribute duplication in M:N): `borrow_date` appears only on `Borrows`, not duplicated on `Member` or `Copy` — pass.
The diagram validates, and — foreshadowing Mapping ER to Relations — this already tells us the eventual schema shape: `Book(ISBN, title)` plus a separate `Book_Author(ISBN, author)` table for the multivalued attribute; `Branch(name, address)`; `Copy(branch_name, copy_number, ISBN)` with a composite key `(branch_name, copy_number)` because it is weak; and `Borrows(member_id, branch_name, copy_number, borrow_date)` because `Borrows` is M:N and needs its own table.
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Putting a descriptive attribute (like `grade`) on an entity instead of the relationship | Designer thinks of it as "belonging" to the student | Attach attributes that depend on the pairing to the relationship diamond |
| Confusing 1:N direction | "N" is written on the side where entities repeat, not where the "1" entity sits — easy to flip | Ask "for one fixed entity on side X, how many on side Y?" and place the count on side Y |
| Forgetting total participation on the owner of a weak entity | The invariant is easy to overlook because the weak entity itself, not the owner, "feels" dependent | Explicitly check: does every owner instance require the weak entity, or does every weak instance require the owner? It's the latter — participation goes on the owner's edge into the identifying relationship |
| Using a single diamond for what is really two independent relationships | Conflating "teaches" and "advises" into one `Instructor`–`Student` diamond | Split into separate relationship sets if the semantics and attributes differ |
| Mixing Chen and crow's-foot symbols in one diagram | Team members trained on different tools | Standardize notation for a document before drawing |
| Modeling a many-to-many relationship as two one-to-many relationships through a fabricated entity, without recognizing it changes the schema | M:N collapses information into a bridge table either way, but doing it accidentally obscures the true constraint | Decide deliberately whether the "bridge" is a real entity (with its own identity) or a pure associative table |
Pioneers & history
The ER model and its diagrammatic notation were introduced to unify the then-competing hierarchical, network, and relational views of data into a single conceptual layer that any of them could implement.
Origins · 1 minPeter Pin-Shan Chen and how this was discovered
Chen, a Taiwanese-American computer scientist, published "The Entity-Relationship Model — Toward a Unified View of Data" while working at MIT, proposing diamonds for relationships and rectangles for entities as a notation that could later be mapped into any of the dominant database paradigms of the era.
Where this matters
ER diagrams are the conceptual design layer used before writing any `CREATE TABLE` statement in production systems, from banking core systems to e-commerce catalogs to university registrars. Database modeling tools such as ER/Studio, MySQL Workbench, Lucidchart, and draw.io all export or import ER diagrams, and many can auto-generate SQL DDL directly from a validated diagram, making the diagram a first-class engineering artifact rather than a whiteboard-only sketch. Enterprise data governance teams use ER diagrams as living documentation, kept alongside the schema so that new engineers and analysts can understand entity relationships without reverse-engineering foreign keys from SQL. Even in systems that ultimately store data in a document or graph database, teams frequently start with an ER diagram to reason about cardinalities and referential constraints before choosing a denormalized or graph-native representation. The discipline of drawing and validating an ER diagram before implementation directly prevents the class of bugs that arise from ambiguous or missing constraints — a duplicate key, a dangling foreign key, or an unenforced one-to-one rule — that are far costlier to fix once a system is in production and populated with real data.
Ask the tutor: How does an ER diagram's cardinality and participation constraints translate step by step into primary keys, foreign keys, and table structure?
What is the difference between Chen notation and crow's-foot notation?
Chen notation uses explicit diamonds for relationship sets and writes cardinality numbers (1, N, M) directly on the connecting lines, making every construct visually distinct and easy to teach from first principles. Crow's-foot notation drops the diamond entirely, drawing relationships as a plain line between two entity rectangles, and encodes cardinality and participation using small symbols (a circle for optional, a bar for mandatory, a "crow's foot" fork for "many") at each end of the line. Crow's-foot is more compact and is what most commercial database modeling tools render by default, but it requires memorizing the endpoint symbols rather than reading an explicit label. Both notations are formally equivalent — any diagram in one can be translated to the other — so the choice is usually a matter of house style or tool support, not expressive power.
Can a relationship set involve more than two entity sets?
Yes — this is called an n-ary relationship, most commonly ternary (three entity sets). For example, a `Supplies` relationship might connect `Supplier`, `Part`, and `Project`, recording that a supplier ships a specific part to a specific project. Ternary relationships cannot always be decomposed into three separate binary relationships without losing information, because the three-way combination itself may be the fact being recorded (supplier X supplies part Y specifically to project Z, not to project W). Cardinality constraints on n-ary relationships are trickier to state precisely, since "how many" must be phrased relative to a fixed combination of the other entity sets, and most textbooks recommend converting complex n-ary relationships into a first-class entity set with binary relationships to each participant when the semantics get unwieldy.
How do multivalued and derived attributes differ from ordinary attributes in the diagram?
An ordinary attribute is drawn as a single oval connected to its entity or relationship, holding exactly one value per instance, like `title` for a `Book`. A multivalued attribute, drawn as a double oval, can hold a set of values for one instance — `phone_number` for a `Customer` who may have several — and eventually becomes its own table when mapped to relations, since a single column cannot hold a variable-length set cleanly. A derived attribute, drawn as a dashed oval, is not stored at all; it is computed from other attributes whenever needed, such as `age` computed from `date_of_birth` and the current date, and is typically not materialized as a column in the final schema unless performance requires caching it.
What does it mean for an entity set to have "partial" participation in a relationship?
Partial participation means that not every instance of the entity set is required to appear in that relationship — some instances may simply not participate. For example, if `Instructor` has partial participation in `Advises`, some instructors may not currently advise any student. This is drawn with a single line, contrasted with total participation's double line. The distinction matters directly for the relational mapping: total participation on the "many" side of a 1:N relationship can sometimes justify a `NOT NULL` foreign key constraint, while partial participation implies the foreign key column may legitimately be null (or the row may simply not reference the relationship at all, depending on how the mapping is structured).
Why does a many-to-many relationship always require its own table when mapped to relations, while a one-to-many relationship sometimes does not?
In a 1:N relationship, the "many" side's table can absorb the relationship as a foreign key column referencing the "one" side, because each "many"-side row is associated with at most one "one"-side row — a single column suffices. In an M:N relationship, a single row on either side may be associated with multiple rows on the other side simultaneously, which cannot be captured by adding one foreign key column to either existing table without duplicating rows or losing information. The only faithful representation is a separate table whose rows are the pairs (plus any relationship attributes), each row naturally holding a foreign key to each side — this is exactly why the ER diagram's cardinality label determines the shape of the schema before any SQL is written.
Is an ER diagram enough to fully specify a database, or is anything left out?
An ER diagram specifies structural constraints precisely — entity sets, keys, relationship cardinalities, and participation — but it does not capture every business rule a real system needs. Constraints like "an employee's salary cannot exceed their manager's salary" or "a reservation cannot overlap another reservation for the same room" are semantic rules that go beyond what rectangles, diamonds, and cardinality labels can express. These are typically enforced later through `CHECK` constraints, triggers, or application-level validation once the diagram has been mapped to relations. The ER diagram's job is to nail down the shape of the data unambiguously; deeper business logic is layered on afterward.