Mermaid Diagram Generator n Editor

Mermaid ER Diagram Syntax

An ER diagram opens with erDiagram, then lists relationships between entities and, optionally, each entity's attribute block.

ConstructMeaningExample
A ||--o{ B : verbOne-to-many: exactly one A relates to zero or more B.
erDiagram
    CUSTOMER ||--o{ ORDER : places
A ||--|{ B : verbOne-to-many where B requires at least one: exactly one A relates to one or more B.
erDiagram
    ORDER ||--|{ ORDER_ITEM : contains
A }o--o{ B : verbMany-to-many: zero or more A relate to zero or more B.
erDiagram
    POST }o--o{ TAG : "tagged with"
ENTITY { type name }An attribute block listing an entity's columns and their types.
erDiagram
    CUSTOMER {
        int id
        string name
    }
int id PKAppending PK after an attribute marks it as the primary key.
erDiagram
    CUSTOMER {
        int id PK
    }
int customer_id FKAppending FK after an attribute marks it as a foreign key referencing another entity.
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER {
        int customer_id FK
    }

Everything together

Mermaid source
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER_ITEM : contains
    CUSTOMER {
        int id PK
        string name
    }
    ORDER {
        int id PK
        int customer_id FK
        date placed_at
    }
    ORDER_ITEM {
        int order_id FK
        int quantity
    }
Mermaid ER Diagram Syntax — full exampleOpen in editor →

Free Online ER Diagram Tool