🗄️ Mermaid

Entity-relationship diagram

Design database schemas that make sense

What is a Entity-relationship diagram?

An ER diagram shows database entities, their attributes and the cardinality of relationships between them (one-to-many, many-to-many). It is the blueprint of every relational database.

Live example

Mermaid code
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER_LINE : contains
    PRODUCT ||--o{ ORDER_LINE : "ordered in"
    CUSTOMER {
      string id PK
      string email UK
    }
    ORDER {
      string id PK
      date created_at
    }
Live example

places

contains

ordered in

CUSTOMER

string

id

PK

string

email

UK

ORDER

string

id

PK

date

created_at

ORDER_LINE

PRODUCT

When to use it

Design a new database schema before the first migration
Document an existing schema for new team members
Discuss data models with non-technical stakeholders

Basic syntax

.mmd
erDiagram
    USER ||--o{ POST : writes
    USER {
      string id PK
      string email
    }

Questions about this diagram

How do I read cardinality symbols like ||--o{ ?

|| means exactly one, o| zero or one, }| one or more, }o zero or more. So CUSTOMER ||--o{ ORDER reads “one customer places zero or more orders”.

Can I generate an ER diagram from SQL?

Yes — paste your CREATE TABLE statements or describe your data and the AI produces the corresponding ER diagram with keys and relationships.

Create your Entity-relationship diagram now

Describe it in plain language — the AI writes the Mermaid code for you.

Open Mermaid Studio