ER Diagram

Free Online ER Diagram Tool

An entity relationship (ER) diagram is a type of diagram that models a database schema: it shows the entities in a system, the attributes each entity has, and how entities relate to one another — for example, one user placing many orders.

Design database schemas and entity relationships using Mermaid syntax. Instant visual preview as you type.

Last updated: · Mermaid v11

Try it live

Live · editablediagram.mmd
Example er diagram rendered by FlowViz
Edit the code — the diagram follows

When to use er diagram

Database design

Plan and document relational schemas before writing a single migration. Typed attributes with PK and FK markers plus explicit cardinalities catch modeling mistakes while they are still cheap to fix.

API documentation

Show the data model underlying your API resources and how they relate. An ER diagram beside the endpoint reference answers the what-does-this-return-and-how-does-it-join questions before anyone has to ask.

System documentation

Give new team members the shape of the data in one picture: entities, keys, and one-to-many relationships. Far faster to absorb than reading a stack of CREATE TABLE statements.

Key syntax

erDiagramDeclare diagram type
ENTITY { }Define an entity with attributes
int id PKPrimary key attribute
int fk FKForeign key attribute
string email UKUnique key attribute
A ||--|| BOne-to-one relationship
A ||--o{ BOne-to-many relationship
A }o--o{ BMany-to-many relationship
: "label"Relationship label
Full ER Diagram syntax reference → More Mermaid examples →

How to create a er diagram with Mermaid

1

Open FlowViz and start with erDiagram.

2

Define each entity with its name and an opening brace: USERS {.

3

Add attributes inside the braces: type name constraint (e.g. int id PK).

4

Close each entity with }.

5

Define relationships between entities on new lines: USER ||--o{ ORDER : "places".

6

Use || for exactly one, o{ for zero or many, |{ for one or many.

7

Add a quoted label after the colon to describe the relationship.

8

Export your schema diagram as SVG.

Frequently asked questions

When should I use an ER diagram instead of a class diagram?

Use an ER diagram for data at rest: tables, their columns and keys, and the cardinality between them. Use a class diagram for behaviour: types, the methods they expose, and how they inherit from one another. They look similar when a class maps one-to-one onto a table, but ER notation says nothing about methods and class notation says nothing about cardinality — so pick by which of those two you actually need to communicate.

What is an ER diagram used for?

Designing and documenting database schemas: the entities, their attributes, and how tables relate to each other.

How do I write relationship cardinality in Mermaid?

With the connector symbols: ||--o{ is one-to-many, ||--|| is one-to-one, and }o--o{ is many-to-many.

Can I list column types in an ER diagram?

Yes — attributes go inside the entity block with a type, a name, and optional PK or FK markers.

Start diagramming now

No signup. No install. Just open the editor and start writing.