Entity-Relationship Modeling

Imagine a university registrar tasked with building a database. It must track students, courses, instructors, and enrollments. Before writing a single line of SQL, someone must answer conceptual questions. What are the things worth recording? What facts describe them? How do they connect to each other? Answering these questions directly in tables is dangerous. It invites redundancy, missed constraints, and designs that fossilize bad decisions. These flaws often go unnoticed until it's too late. Entity-Relationship (ER) modeling exists to answer these questions first. It does so in a notation independent of any particular database system. The ER model gives designers a small, disciplined vocabulary. This includes entities, attributes, relationships, and cardinality constraints. These describe the structure of an application's data at a conceptual level. It sits deliberately above the physical and logical layers. An ER diagram says nothing about how data is stored, indexed, or queried. It only shows what exists and how it relates. This separation echoes the broader theme of Data Abstraction and Schemas. There, a conceptual schema mediates between real-world meaning and physical implementation. Why does this matter in real systems? Every production database began life as a conceptual model. This includes a hospital's patient records or an airline's reservation system. This holds true whether or not anyone drew it explicitly. Skipping this stage rarely saves time. It usually reappears later as expensive schema migrations. It can also cause ambiguous foreign keys or inconsistent business rules. These rules often end up encoded inconsistently across an application. Companies pay database architects specifically to get this stage right. A flawed entity model radiates errors through every application built on top of it. This article develops the ER model rigorously. It gives precise definitions of entities and entity sets. It covers attributes and their types, relationships, and relationship sets. It also explains cardinality constraints — one-to-one, one-to-many, many-to-many. These constraints encode business rules. This article builds the vocabulary and reasoning skills needed first. These are essential before drawing ER Diagrams. They also prepare readers for the systematic translation known as Mapping ER to Relations.

Key takeaways
  • An entity is a distinguishable real-world object; an entity set groups entities sharing the same attributes.
  • Attributes describe entities and relationships; they can be simple, composite, single-valued, multivalued, or derived.
  • A relationship associates two or more entities; a relationship set is a collection of such associations, itself possibly bearing attributes.
  • Cardinality constraints (1:1, 1:N, M:N) capture how many entities on each side can participate in a relationship instance.
  • Keys — candidate, primary, and (for weak entities) partial keys — enforce uniqueness at the conceptual level.
  • ER modeling is a design discipline, not a syntax: getting the entities and cardinalities right determines whether the eventual relational schema is sound.
The core insight

The Entity-Relationship model captures what exists and how it connects in the real world, deliberately before deciding how it will be stored.

The idea

An entity is a specific, distinguishable object in the domain being modeled — a particular student, a particular course offering, a particular book copy. An entity set is a collection of entities of the same type that share the same set of attributes, analogous to a class in object-oriented terms but without behavior: `Student`, `Course`, `Instructor`. Formally, an entity set is a set of entities together with a schema, a named list of attributes, and every entity in the set is an instance of that schema.

Attributes are the properties that describe entities. An attribute has a domain, the set of legal values it may take. Attributes come in several flavors that matter for accurate modeling:

  • Simple vs. composite: `name` might decompose into `first_name` and `last_name`.
  • Single-valued vs. multivalued: an instructor typically has one office, but may have several phone numbers.
  • Stored vs. derived: `age` can be derived from `date_of_birth` and the current date rather than stored redundantly.

A relationship is an association among two or more entities — e.g., a specific student enrolled in a specific course section. A relationship set is a collection of relationships of the same type, defined over a set of participating entity sets called its degree. A relationship connecting two entity sets is binary (the overwhelming majority in practice); relationships among three or more entity sets are ternary or, more generally, n-ary. Relationship sets can themselves carry attributes — the grade earned in an enrollment naturally belongs to the `Enrolls` relationship, not to `Student` or `Course` alone, since it depends on the pairing of both.

Cardinality constraints (also called mapping cardinalities) restrict how many entities can participate in a relationship instance on each side. For a binary relationship between sets A and B, the four canonical cases are:

  • One-to-one (1:1): an entity in A associates with at most one entity in B, and vice versa.
  • One-to-many (1:N): an entity in A associates with many entities in B, but each entity in B associates with at most one in A.
  • Many-to-one (N:1): the mirror image of 1:N.
  • Many-to-many (M:N): entities on both sides may associate with multiple entities on the other side.

A related but distinct notion is participation constraint: total participation means every entity in the set must appear in at least one relationship instance (e.g., every course section must have an instructor); partial participation means participation is optional. Cardinality answers "how many," participation answers "must it happen at all." Both are business rules discovered by talking to domain experts, not facts inferable from data alone. Finally, a weak entity set is one that has no full key of its own — its instances are identified only in combination with a related identifying (or owner) entity set through a relationship called an identifying relationship. A weak entity carries a partial key (also called a discriminator), which distinguishes its instances only within the scope of one owner. A classic example: `Room` entities identified only by room number within a specific `Building`; the same room number recurs across buildings, so `Room` cannot stand alone as a strong entity set.

How it works

Building an ER model is an iterative, human-driven process, but it follows a repeatable procedure. The steps below describe the design algorithm a modeler actually executes, moving from an informal requirements narrative to a validated conceptual schema. ``` ALGORITHM BuildERModel(requirements_text):

# Phase 1: identify entity sets candidates <- extract_nouns(requirements_text) entity_sets <- {} for each noun in candidates: if noun denotes a distinguishable, independently meaningful object: entity_sets.add(noun) else if noun is a property of some object: defer to Phase 2 # it may become an attribute instead

# Phase 2: assign attributes and keys for each E in entity_sets: attributes(E) <- properties describing E, classified as simple | composite | single-valued | multivalued | derived determine candidate_keys(E) # minimal attribute sets that uniquely identify instances if no candidate key exists: mark E as WEAK identify partial_key(E) else: choose primary_key(E) from candidate_keys(E)

# Phase 3: identify relationships relationship_sets <- {} for each verb phrase connecting two or more entity sets: R <- new relationship set over the connected entity sets determine degree(R) # binary, ternary, ... determine cardinality(R) # 1:1, 1:N, M:N per pair determine participation(R) # total or partial, per entity set if R connects a weak entity set to its owner: mark R as IDENTIFYING attach any attributes(R) that depend on the pairing, not on one side alone relationship_sets.add(R)

# Phase 4: validate for each E in entity_sets: assert E has a well-defined key (own key, or partial key + identifying relationship) for each R in relationship_sets: assert cardinality(R) and participation(R) reflect actual business rules assert no attribute is misattributed to an entity when it truly depends on a relationship return (entity_sets, relationship_sets) ``` The subtlety is entirely in Phases 1–3: deciding whether something is an entity, an attribute, or a relationship is a modeling judgment, not a mechanical parse. `Address` might be a composite attribute of `Customer` in one design, or a full-fledged `Address` entity set (shared by multiple customers, with its own attributes like `zip_code`) in another — the correct choice depends on whether addresses need independent identity, history, or sharing across entities. Phase 4's validation loop is where most real-world modeling errors surface: a missing key, a cardinality that silently forbids a legitimate business scenario, or an attribute placed on the wrong construct. Consider the university example concretely: `Student` and `Course` are entities; `Enrolls` is the relationship set connecting them, carrying the attribute `grade`; and because a student can enroll in many courses and a course can have many students, `Enrolls` has M:N cardinality. `Instructor` teaches `Course` sections through a `Teaches` relationship that is typically N:1 (many sections, one instructor per section, in a simplified model) with total participation on the `Section` side (every section must have an instructor) and partial participation on the `Instructor` side (not every instructor must be teaching right now).

Figure
Entity-Relationship diagram: Student, Course, and Instructor with cardinalities
Student Course Instructor Enrolls Teaches M N N 1 grade sID courseID Rectangles = entity sets · Diamonds = relationship sets · Ovals = attributes · underline = key

Complexity & correctness

ER modeling is not an algorithm executed by a machine on quantifiable input size; its "complexity" is best understood in terms of the design-space search it performs and the guarantees it delivers once complete. Still, several honest complexity-style claims can be stated.

Size of the model. If a domain has nn entity sets and each pair of entity sets is examined once for a potential relationship, exhaustively checking all pairwise associations costs O(n2)O(n^2) comparisons; in practice, most of the (n2)\binom{n}{2} pairs have no direct relationship, and a competent modeler prunes this search using domain knowledge rather than brute force, so the effective work is closer to O(n+m)O(n + m) where mm is the number of actual relationship sets identified (typically m=O(n)m = O(n) in well-designed schemas, since most entities participate in only a small constant number of relationships).

Validation cost. Phase 4's validation loop checks each entity set for a valid key (O(n)O(n) checks, each O(1)O(1) to O(k)O(k) where kk is the number of candidate-key attributes examined) and each relationship set for correct cardinality and participation (O(m)O(m) checks). Total validation is O(n+m)O(n + m), linear in the size of the model — cheap compared to the intellectual cost of discovering the correct cardinalities in the first place, which depends on domain understanding rather than computation.

Correctness argument. What does it mean for an ER model to be "correct"? There is no automatic verifier against ground truth, since the ground truth is the real-world business, not a formal specification. Instead, correctness is argued via three invariants a completed model must satisfy: 1. Identifiability invariant. Every entity set has a way to uniquely identify its instances: either a primary key drawn from its own attributes, or (for a weak entity set WW with identifying owner OO) a partial key on WW combined with the primary key of OO reachable through the identifying relationship. Proof sketch of necessity: if this invariant fails, two distinct real-world entities could map to indistinguishable representations, making it impossible to later formulate correct queries or updates — the eventual relational schema (see Mapping ER to Relations) would have no way to target a single row. 2. Attribute-placement invariant. An attribute is attached to an entity set only if its value depends functionally on that entity set alone; it is attached to a relationship set only if its value depends on the combination of participants. Justification: violating this — e.g., storing `grade` on `Student` instead of on `Enrolls` — conflates a fact that varies per course with an entity that doesn't, producing an update anomaly the moment a student takes a second course. 3. Cardinality-fidelity invariant. The stated cardinality and participation constraints must be neither stricter nor looser than the real business rule. Justification: an overly strict constraint (declaring `Teaches` as 1:1 when an instructor can teach multiple sections) makes legitimate data unrepresentable; an overly loose constraint (declaring M:N when the rule is really 1:N) fails to enforce a rule the application relies on, silently permitting invalid states once the schema is implemented.

Tradeoffs. ER modeling trades upfront time for downstream safety. Its cost is genuinely human: workshops with domain experts, iteration, and diagrams that must be revisited as understanding deepens. Its benefit is that mistakes caught at this stage — a missing cardinality, a wrongly-scoped attribute — cost orders of magnitude less to fix than mistakes discovered after a relational schema, application code, and production data all depend on the wrong assumption. The model is also deliberately implementation-agnostic; this is a strength (portability across relational, and even non-relational back ends) but also a limitation, since some legitimate physical concerns (denormalization for performance, partitioning) are consciously left for a later design stage.

Worked example

Consider modeling a small library system with the following requirements, given informally: > "The library tracks books by ISBN, title, and a list of authors. Each physical copy of a book has a unique barcode and a condition status. Members, identified by member ID, name, and email, can borrow copies. A borrowing records the date borrowed and the due date. Each book copy is shelved in a specific room of a specific branch; room numbers repeat across branches." Walking through `BuildERModel`:

Phase 1 — entity sets. Candidate nouns: `Book`, `Copy`, `Member`, `Branch`, `Room`, `Borrowing`. `Borrowing` is actually a verb-derived association, deferred to Phase 3. `Book`, `Copy`, `Member`, `Branch` are clearly independent objects. `Room` is suspicious — flagged for weak-entity treatment because "room numbers repeat across branches."

Phase 2 — attributes and keys.

Entity setAttributesKey situation
`Book``ISBN` (simple), `title` (simple), `authors` (multivalued)`ISBN` is a candidate key → primary key
`Copy``barcode` (simple), `condition` (simple)`barcode` is a candidate key → primary key
`Member``memberID`, `name` (composite: first/last), `email``memberID` → primary key
`Branch``branchName`, `address``branchName` → primary key
`Room``roomNumber`No standalone key (repeats across branches) → weak entity, partial key = `roomNumber`

Phase 3 — relationships.

RelationshipConnectsCardinalityParticipationAttributes on R?
`HasCopy``Book`–`Copy`1:N (one book, many copies)`Copy` total (every copy is of some book)none
`Borrows``Member`–`Copy`M:N (a member borrows many copies over time; a copy is borrowed by many members over time)partial on both sides`date_borrowed`, `due_date`
`LocatedIn``Room`–`Branch` (identifying)each `Room` belongs to exactly one `Branch``Room` total, identifying relationshipnone
`ShelvedAt``Copy`–`Room`N:1 (many copies, one room)`Copy` totalnone

Phase 4 — validation. `Room`'s identifiability is checked: its full key becomes (`branchName`, `roomNumber`) via the identifying relationship `LocatedIn` — exactly matching the requirement that room numbers repeat across branches but not within one. `Borrows` correctly carries `date_borrowed` and `due_date`, since a due date depends on the specific pairing of a member and a copy at a specific time, not on either alone. Notice the deliberate catch: had `due_date` been placed on `Copy` instead, the schema would be unable to represent the same copy being borrowed twice with two different due dates — exactly the kind of anomaly the attribute-placement invariant is designed to prevent. This trace demonstrates the discipline end-to-end: the tricky decisions (weak entity for `Room`, relationship attributes on `Borrows`, correctly distinguishing 1:N from M:N for `HasCopy` versus `Borrows`) are exactly where real design skill is exercised, not in the mechanical parts.

Common pitfalls & traps

PitfallWhy it happensConsequence
Modeling an attribute as an entity (or vice versa)Failing to ask whether the "thing" needs independent identity or is shared/reusedEither an over-engineered schema with needless joins, or a schema that cannot represent shared/reused values
Placing a relationship's attribute on one participating entityNot recognizing the attribute depends on the pairing, not one sideUpdate anomalies: the same entity ends up needing multiple, contradictory attribute values
Wrong cardinality (e.g., 1:1 where the rule is really 1:N)Designer generalizes from a small or biased example ("in our data, so far, each teacher had one section")Legitimate future data becomes unrepresentable; forces awkward schema changes later
Forgetting a weak entity's identifying relationshipTreating a dependent object (like `Room`) as though it had a standalone keyAmbiguous or colliding identifiers once real data is loaded
Confusing participation with cardinalityBoth look like "constraints near the relationship" in a diagramA total-participation rule gets silently dropped, allowing orphaned or invalid entities
Over-modeling ternary relationships as pairs of binary onesBinary relationships feel simpler to drawLoses information: a true three-way fact (e.g., supplier-part-project) cannot be reconstructed correctly from three binary relationships

Pioneers & history

The ER model was introduced as a way to unify the then-competing camps of hierarchical, network, and relational database design around a single conceptual notation, one that any of those physical models could implement. A photograph-style portrait context: Peter Chen presenting the entity-relationship approach at a database conference in the mid-1970s, sketching diamond-and-rectangle diagrams meant to be readable by non-programmers and DBAs alike, bridging business analysts and implementers.

Origins · 1 minPeter Pin-Shan Chen and how this was discovered
PP
Peter Pin-Shan Chen
born 1944 · Introduced the Entity-Relationship model as a unifying conceptual notation for database design

History
1970
— Codd publishes the relational model, providing the target formalism ER designs would later be mapped onto.
1976
— Chen publishes "The Entity-Relationship Model: Toward a Unified View of Data," introducing entities, relationships, and diagrammatic notation.
1980
s — ER modeling becomes standard practice in CASE (computer-aided software engineering) tools for database design.
1990
s — Extensions such as the Enhanced ER (EER) model add generalization, specialization, and aggregation constructs.
2000
s–present — ER concepts persist inside UML class diagrams and modern schema-design tools, even as physical storage engines diversify.

Where this matters

ER modeling remains the standard first step in designing relational databases across virtually every industry: banking systems model `Account`, `Customer`, and `Transaction`; hospitals model `Patient`, `Provider`, and `Encounter`; e-commerce platforms model `Product`, `Order`, and `Customer`. Database design tools (from open-source schema designers to enterprise CASE tools) let architects draw ER diagrams and then generate `CREATE TABLE` statements automatically, which is possible precisely because the systematic translation in Mapping ER to Relations is well-defined once entities, attributes, relationships, and cardinalities are pinned down. Object-relational mapping frameworks used in modern application development implicitly encode ER-style thinking: a class with a foreign key relationship is a direct descendant of an ER relationship set with cardinality constraints. Even NoSQL and document-oriented systems, which reject some relational normalization discipline, still benefit from an initial ER-style analysis to understand what entities and associations exist before deciding how to denormalize them into documents. Understanding ER modeling well is also foundational for anyone learning ER Diagrams as a communication tool between technical and non-technical stakeholders, and for anyone who will later study normalization and the relational algebra that operates on the schemas ER models produce.

Ask the tutor: How do I decide whether a many-to-many relationship set with attributes should become its own table when mapping this ER model to relations?

Is an ER diagram the same thing as a database schema?

No. An ER diagram is a conceptual-level artifact describing entities, attributes, relationships, and constraints in a notation independent of any DBMS. A database schema (in the relational sense) is a logical-level artifact: tables, columns, keys, and foreign keys expressed in a specific data model, typically the relational model. The systematic process of turning one into the other — deciding which entity sets become tables, how relationships become foreign keys or junction tables, and how weak entities inherit keys — is a distinct, well-defined procedure often called mapping ER to relations. Confusing the two stages is a common source of premature physical-design decisions creeping into what should be a purely conceptual exercise.

Why bother with ternary relationships instead of decomposing them into three binary relationships?

A genuine three-way fact can lose information when split into pairs. Consider `Supplier`, `Part`, and `Project`, where the real-world rule is "supplier S supplies part P to project J." Decomposing this into `Supplies(Supplier, Part)`, `Uses(Part, Project)`, and `Assigned(Supplier, Project)` cannot reconstruct which supplier supplies which part to which specific project — the joint fact is lost, since each binary relationship only captures a pairwise projection. A single ternary relationship set preserves the full three-way association, which is why ER modeling explicitly supports relationships of degree three or more rather than forcing everything into pairs.

Can an entity set participate in a relationship with itself?

Yes — this is called a recursive (or unary) relationship. A classic example is an `Employee` entity set with a `Supervises` relationship connecting employees to other employees, where one employee supervises another. Because both roles are filled by the same entity set, the relationship notation typically labels each connecting line with a role name (e.g., "supervisor" and "supervisee") to disambiguate which entity plays which part in a given instance. Cardinality and participation constraints apply exactly as in any binary relationship, just evaluated with respect to the two distinct roles rather than two distinct entity sets.

How do you decide between modeling something as a multivalued attribute versus a separate entity set?

The deciding factor is whether the "thing" needs independent identity, additional attributes of its own, or must be referenced from elsewhere. A student's phone numbers, with no further structure, can remain a multivalued attribute. But if phone numbers needed their own attributes (type: mobile/home, verified: yes/no) or needed to be shared and independently tracked, promoting them to a full entity set connected by a relationship is the correct choice. As a rule of thumb, multivalued attributes work for simple, self-contained repeated facts; entity sets are needed once the repeated fact grows its own structure or relationships.

What's the difference between a candidate key and a primary key in ER modeling?

A candidate key is any minimal set of attributes that uniquely identifies each entity in an entity set; an entity set can have several candidate keys (for example, a `Student` entity set might be uniquely identified by either `studentID` or `email`). The primary key is the single candidate key the designer chooses as the canonical identifier, typically for stability and simplicity — an ID number rather than an email address that might change. Other candidate keys are still valid uniqueness constraints and are often preserved as unique constraints even after one is elevated to primary key status in the resulting relational schema.

Does total participation mean the same thing as a "not null" constraint?

They are related but conceptually distinct. Total participation is an ER-level statement that every entity in an entity set must appear in at least one instance of a specific relationship — a business rule about relationships, not about a single column's value. When mapped to relations, total participation on the "many" side of a relationship is often enforced, in part, through a not-null foreign key column, but the ER concept itself is about mandatory participation in an association, and its faithful translation can also require additional constraints (like a check that at least one entry exists) beyond a simple not-null.

Why does the article insist ER modeling should happen before choosing a relational, document, or graph database?

Because the entities, attributes, and associations in a domain are facts about the real world, independent of storage technology, while the choice of relational tables, JSON documents, or graph nodes and edges is an implementation decision. Doing ER analysis first forces the team to agree on what the data actually means and what rules it must obey before locking in a storage-specific structure that is expensive to change. Even teams ultimately choosing a non-relational system benefit from this discipline, since it surfaces cardinalities and dependencies that later inform how documents should be nested or graphs structured.

Before this

Where this leads