# Introduction to the ER Model

> The ER (Entity-Relationship) model is a conceptual tool for planning a database's structure before any tables are created. It maps out entities (real-world objects such as a customer or order), their attributes (properties that generally become columns), and the relationships between them, each with a cardinality of one-to-one, one-to-many or many-to-many.

Canonical: https://devsunite.com/resources/core-subjects/dbms/introduction-to-er-model
Last updated: 2026-11-22

Subject: DBMS · Category: RDBMS · 4 min read

The Entity-Relationship (ER) model is a conceptual tool for planning a database's structure before any tables actually get created. Instead of jumping straight into `CREATE TABLE` statements, database designers first sketch out the real-world things the database needs to represent, and how those things relate to each other.

## The three core building blocks

**Entities** are the real-world objects or concepts being modeled, a customer, a product, an order. Each entity type becomes, roughly, a table.

**Attributes** are properties of an entity. A `Customer` entity might have attributes like `name`, `email`, and `phone`. Attributes generally become columns.

**Relationships** describe how entities connect to each other. A `Customer` *places* an `Order`. Relationships carry a cardinality, describing how many of one entity can relate to how many of another:

- **One-to-one (1:1)**: one row in table A relates to exactly one row in table B, and vice versa. A `Person` and their `Passport` is a classic example.
- **One-to-many (1:N)**: one row in table A can relate to many rows in table B, but each row in B relates back to only one row in A. One `Customer` can place many `Orders`, but each `Order` belongs to exactly one `Customer`.
- **Many-to-many (M:N)**: rows in both tables can relate to multiple rows in the other. A `Student` can enroll in many `Courses`, and each `Course` can have many `Students`.

## Why plan this out before writing SQL

Designing entities and relationships on paper (or a whiteboard) first catches structural mistakes early, before real data and real application code depend on the schema. It's dramatically cheaper to realize "wait, this should actually be many-to-many" during planning than after a production application has been built assuming a one-to-many relationship.

## A worked example

Modeling a simple library system:

- **Entities**: `Member`, `Book`, `Loan`.
- **`Member` attributes**: `member_id`, `name`, `email`.
- **`Book` attributes**: `isbn`, `title`, `author`.
- **Relationship**: a `Member` *borrows* a `Book`, tracked through a `Loan`.

Is `Member`-borrows-`Book` one-to-many, or many-to-many? In reality, it's many-to-many: one member can borrow many books over time, and one specific book (thinking of the library owning multiple physical copies, or the same title being borrowed by different people at different times) can be borrowed by many different members. A many-to-many relationship like this can't be represented with a simple foreign key on either side, it needs a separate table (here, `Loan`) sitting between them, with foreign keys pointing to both `Member` and `Book`, plus its own attributes like `loan_date` and `due_date`.

This is exactly the kind of structural realization the ER model surfaces before any table gets built: recognizing early that a naive one-to-many assumption is wrong, and that a linking table is actually required.

## Where this matters in real systems

Every well-designed relational schema, whether it was drawn out formally or just reasoned through informally, started with this kind of thinking: what are the real entities, what attributes do they need, and critically, what is the real cardinality of each relationship between them. Getting a relationship's cardinality wrong early (assuming one-to-many when it's really many-to-many) is one of the most common, and most expensive-to-fix-later, mistakes in database design.

## What interviewers actually ask about the ER model

- **"What are the three core components of an ER model?"** Entities, attributes, and relationships.
- **"What's the difference between one-to-many and many-to-many relationships?"** One-to-many: one row on the "one" side relates to many rows on the "many" side, but not vice versa. Many-to-many: rows on both sides can relate to multiple rows on the other, which requires a separate linking table to represent.
- **"Why can't a many-to-many relationship be represented with a single foreign key?"** A foreign key only points from one row to one other row; representing "many relates to many" needs a separate table holding pairs of foreign keys, one to each side.
- **"Walk me through modeling a real-world scenario as an ER diagram."** Interviewers often ask this live, expecting the candidate to identify entities, attributes, and relationship cardinality out loud, not just recite the definitions.

## Key takeaways

- The ER model is a planning tool for database structure, built from entities, attributes, and relationships.
- Relationships have a cardinality: one-to-one, one-to-many, or many-to-many.
- Many-to-many relationships need a separate linking (junction) table to represent, a single foreign key isn't enough.
- Getting cardinality wrong early is one of the costliest mistakes to fix once real data and application code exist.

## Related

- [Previous: What Is an RDBMS?](https://devsunite.com/resources/core-subjects/dbms/what-is-rdbms)
- [Next: How to Draw an ER Diagram](https://devsunite.com/resources/core-subjects/dbms/how-to-draw-an-er-diagram)
- [More in RDBMS: Introduction to the Relational Model](https://devsunite.com/resources/core-subjects/dbms/introduction-to-relational-model)
- [More in RDBMS: Keys in the Relational Model](https://devsunite.com/resources/core-subjects/dbms/keys-in-relational-model)
- [All 174 DBMS interview questions](https://devsunite.com/resources/core-subjects/dbms)
