SQL to ER Diagram
Home › SQL to Mermaid

SQL to Mermaid

Paste your SQL CREATE TABLE statements and get a Mermaid erDiagram you can copy straight into Markdown, GitHub, or your docs — plus a live, interactive diagram.

Open the diagram tool →
No signup · nothing uploaded · export PNG / SVG / Mermaid / DBML · shareable link

How it works

  1. Paste your SQL schema into the editor (PostgreSQL, MySQL, SQLite or SQL Server).
  2. The diagram renders instantly so you can check it.
  3. Click Export → Mermaid and copy the erDiagram code.
  4. Drop it into any Mermaid-aware Markdown (GitHub, GitLab, Notion, Obsidian…).

Example

This SQL:

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT UNIQUE
);
CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  user_id INT REFERENCES users(id)
);

…exports as this Mermaid:

erDiagram
    users {
        serial id PK
        text email
    }
    posts {
        serial id PK
        int user_id FK
    }
    users ||--o{ posts : "user_id"

Copy it from Export → Mermaid. Try it with your own →

Guide

The export maps your SQL one-to-one onto Mermaid's erDiagram grammar: each CREATE TABLE becomes an entity block, columns keep their types, PRIMARY KEY / FOREIGN KEY / UNIQUE become PK / FK / UK markers, and each foreign key becomes a relationship line with the right cardinality — ||--o{ for a plain one-to-many, ||--|| for a unique foreign key.

Where the output works: GitHub and GitLab Markdown (fenced as a mermaid code block), Notion code blocks, Obsidian, GitBook, MkDocs with mkdocs-material, and the Mermaid Live Editor. If your target renderer chokes on something, the usual culprit is an exotic column type — rename it to a simple word (string, int) in the export and it will render anywhere.

Why convert via a diagram tool instead of by hand: the live preview catches mistakes before you paste. If the edge between orders and customers looks wrong on the canvas, the Mermaid will be wrong too — fix the SQL, re-export. The canvas is the proof, the export is the artifact.

Why use it

SQL → MermaidSQL → DBMLSQL → PlantUMLPNG / SVG

FAQ

How do I convert SQL to a Mermaid ER diagram?

Paste your CREATE TABLE statements, then click Export → Mermaid and copy the erDiagram code. Foreign keys become relationships.

Where can I use the Mermaid output?

Anywhere Mermaid renders: GitHub & GitLab Markdown, Notion, Obsidian, docs sites, and the Mermaid Live Editor.

Is my schema uploaded anywhere?

No. Everything runs locally in your browser — your schema is never uploaded to or stored on any server.

Is it free?

Yes. It is completely free and open source, with no account or sign-up required.

Related