How to Create an ER Diagram: Step-by-Step Guide
Table of Contents
An entity-relationship diagram (ERD) is a visual map of your database — showing what data you store, what properties each thing has, and how everything connects. This guide walks through building one from scratch, even if you have never drawn one before.
What Is an ER Diagram and When Do You Need One?
An ER diagram shows three things:
- Entities — the objects or things in your system (User, Product, Order, Post)
- Attributes — the properties of each entity (User has a name, email, created date)
- Relationships — how entities connect (a User places many Orders)
You need an ERD when you are:
- Designing a new database schema before writing any code
- Explaining an existing database to a new team member
- Reviewing a data model for a code review or architecture discussion
- Completing a database design assignment for a course
- Documenting a system for compliance or audit purposes
The diagram does not run any code or create any tables itself — it is a communication tool. Once it is agreed on, you write the SQL (or whatever your ORM uses) to build the real schema.
Step 1: Identify Your Entities
Start by listing every distinct "thing" your system needs to track. Ask: what nouns does the business care about?
For an online bookstore, the answer might be: Customer, Book, Author, Order, Review, Category.
Rules for identifying entities:
- Entities are nouns, not actions
- Each entity should have multiple instances (many customers, many books)
- If you can describe something with a set of attributes it probably belongs on its own entity
- Do not confuse entities with attributes — "City" could be an entity (if you track city population, region, etc.) or just an attribute on an Address
Start with 4–8 entities. You can add more as you work through the relationships. Starting too large makes the diagram unreadable.
Step 2: Define Attributes for Each Entity
For each entity, list the data points you need to store. Focus on what the system actually uses — not every column you might ever want.
Example for a Customer entity:
- id (primary key — uniquely identifies each customer)
- name
- email (should be unique)
- phone (optional)
- createdAt (when the account was created)
Mark your primary key with PK. If the table references another entity, you will add a foreign key (FK) attribute later when you define the relationship.
Tip: Do not over-specify at this stage. The ERD is a design tool, not a contract. You will add and remove attributes as the design evolves. Start lean.
Sell Custom Apparel — We Handle Printing & Free ShippingStep 3: Map the Relationships Between Entities
Now connect the entities. For each pair that has a connection, define:
- The verb that describes the relationship ("places", "belongs to", "contains")
- The cardinality — how many of each can exist on each side
The three cardinality types:
| Type | Meaning | Example |
|---|---|---|
| One-to-one | Each A has exactly one B, and each B has exactly one A | User has one Profile |
| One-to-many | One A can have many B, but each B belongs to one A | Customer places many Orders |
| Many-to-many | One A relates to many B, and one B relates to many A | Student enrolls in many Courses; Course has many Students |
Many-to-many relationships require a junction (bridge) table in a relational database. For example, a Student-Course many-to-many becomes three entities: Student, Enrollment, Course — where Enrollment has foreign keys to both.
Step 4: Write or Draw the Diagram
With your entities, attributes, and relationships defined, you are ready to build the diagram. Use the free ERD maker above:
- Type
erDiagramon the first line - Define each entity with its attributes inside curly braces
- Add relationship lines below the entity definitions
- The diagram renders live as you type
Example using the bookstore from Step 1:
erDiagram
CUSTOMER {
int id PK
string name
string email UK
}
BOOK {
int id PK
string title
decimal price
int authorId FK
}
ORDER {
int id PK
int customerId FK
date createdAt
}
CUSTOMER ||--o{ ORDER : places
ORDER }o--|| BOOK : contains
When the diagram looks right, export as PNG or SVG for sharing or documentation.
Step 5: Review and Refine
Once you have a first draft, ask these questions:
- Does every entity have a primary key?
- Are all many-to-many relationships represented with junction tables?
- Are foreign keys correctly placed on the "many" side of each relationship?
- Is any attribute stored on more than one entity? (This is usually a normalization issue.)
- Are there entities that are never connected to anything? (Usually a sign they belong as attributes on another entity.)
Show the diagram to someone who knows the business problem but not the database. If they can read the diagram and understand what data the system stores, it is a good design. If they have questions the diagram cannot answer, add the missing information.
Common ER Diagram Mistakes
- Missing primary keys — every entity needs a unique identifier. If the business does not have one, add a surrogate key (auto-incrementing integer or UUID).
- Many-to-many without a junction table — relational databases cannot directly represent many-to-many relationships. You need a third table.
- Attributes as entities — if something only has one property (like a city name with no other stored data), it is an attribute, not an entity.
- Too many entities in one diagram — if you have 20+ entities, split the diagram into functional areas. One diagram per bounded context is easier to read and maintain.
- Confusing the diagram with the schema — the ERD is a design tool. The actual database tables are built from the schema, not by exporting the image.
Build Your First ER Diagram Free
No signup, no install. Type your schema, export PNG or SVG. Takes less than 5 minutes for a basic design.
Open Free ERD MakerFrequently Asked Questions
What is the easiest way to create an ER diagram?
The fastest approach for most developers is a text-based tool using Mermaid erDiagram syntax. You describe your entities and relationships as plain text, and the tool renders the diagram automatically. No drag and drop, no manual layout. Open the free ERD maker above and type erDiagram on the first line to get started.
What are the three components of an ER diagram?
An ER diagram has three main components: entities (the objects or things in your system, like User or Product), attributes (the properties of each entity, like name or price), and relationships (how entities connect to each other, including cardinality — one-to-one, one-to-many, or many-to-many).
How do I show a many-to-many relationship in an ER diagram?
Many-to-many relationships are represented with a junction table (also called a bridge or associative table) that sits between the two entities and holds foreign keys to both. For example, Student and Course connected many-to-many becomes Student, Enrollment, and Course — with Enrollment containing studentId FK and courseId FK.

