N
NJHTools

ER Diagram Online

Describe tables, columns and relationships in Mermaid text and get an entity-relationship diagram with crow's foot notation, live preview and SVG or PNG export. Free, no signup, and it runs in your browser.

Zoom
100%
Export
Mermaid code25 lines

Tab inserts spaces. Press Esc, then Tab, to move focus out. Autosaved in this browser.

PreviewLoading Mermaid…

Rendering…

Example ER diagram code

This is the Mermaid source loaded in the editor above. Copy it into a Markdown file inside a ```mermaid block and GitHub, GitLab, Notion or Obsidian will render it.

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER_ITEM : contains
    PRODUCT ||--o{ ORDER_ITEM : "appears in"
    CUSTOMER {
        int id PK
        string email UK
        string name
    }
    ORDER {
        int id PK
        int customer_id FK
        date created_at
        string status
    }
    ORDER_ITEM {
        int order_id FK
        int product_id FK
        int quantity
    }
    PRODUCT {
        int id PK
        string sku UK
        decimal price
    }

ER diagram syntax cheat sheet

SyntaxWhat it does
erDiagramStart an entity-relationship diagram.
A ||--o{ B : labelRelationship with crow's foot ends and a label (quote labels with spaces).
|| / |oExactly one / zero or one (left side; mirrored as || and o| on the right).
}| / }oOne or more / zero or more (left side; |{ and o{ on the right).
-- vs ..Solid line = identifying relationship, dotted = non-identifying.
ENTITY { type name PK }Attributes with type and name. Keys: PK, FK, UK.

How to make a Mermaid ER diagram

  1. 1Start the code with erDiagram.
  2. 2Add relationships such as CUSTOMER ||--o{ ORDER : places.
  3. 3List each entity's attributes with type and name in braces.
  4. 4Mark keys with PK, FK or UK.
  5. 5Export as SVG or PNG, or copy a share link.

Crow's foot cardinality

Each side of a relationship has two characters: |o means zero or one, || exactly one, }o zero or more and }| one or more. They are mirrored on the right side, so CUSTOMER ||--o{ ORDER reads "one customer has zero or more orders".

A relationship needs a label after the colon. Use a verb such as places or contains so the diagram reads as a sentence.

Attributes and keys

Add columns in braces after the entity name, one per line as type then name, such as int id PK and string email UK.

PK marks a primary key, FK a foreign key and UK a unique key. You can add a quoted comment after the key to note constraints.

Identifying vs non-identifying

Two dashes (--) draw a solid line for an identifying relationship, where the child cannot exist without the parent. Two dots (..) draw a dashed line for a non-identifying one.

Model one bounded area at a time; a diagram of 10 to 15 entities stays readable.

Frequently Asked Questions

How do I draw a one-to-many relationship?↓

Write PARENT ||--o{ CHILD : has. || is exactly one on the parent side and o{ is zero or more on the child side.

How do I add primary and foreign keys?↓

Inside the entity's braces, add PK or FK after the attribute, for example int customer_id FK.

Can I generate SQL from the ER diagram?↓

No. Mermaid draws the diagram only. It is meant for documenting and discussing a schema, not for generating DDL.

Will this diagram render on GitHub, GitLab or Notion?↓

Yes, all three render Mermaid. On GitHub and GitLab, put the code in a fenced code block that starts with ```mermaid. In Notion, add a code block and set its language to Mermaid. Hosted platforms may run an older Mermaid version, so very new syntax can fail there.

How do I export the diagram as PNG or SVG?↓

Use the export buttons above the preview. SVG stays sharp at any size and suits docs and slides; PNG is a raster image that works anywhere images are accepted. Both are created in your browser.

How does sharing work, and is my diagram private?↓

The share link stores your diagram code in the URL hash, the part after #, which browsers do not send to servers. Nothing is uploaded, and your work is autosaved in your own browser. Anyone with the link can see the diagram, so share it only with people you trust.

Last updated: