SQL to Mermaid ER Diagram
Paste CREATE TABLE SQL and get a Mermaid erDiagram you can paste into any GitHub README, GitLab wiki, Notion page, or Markdown renderer that supports Mermaid. Entities show column names, SQL types, and PK/FK markers; foreign key relationships are rendered as labeled connector lines with the correct cardinality notation.
How to use the SQL to Mermaid ER Diagram
Paste your CREATE TABLE DDL, click Generate Mermaid, and copy the output. The output is already wrapped in a Markdown fenced code block with the mermaid language tag so you can paste it directly into a GitHub README or any Markdown editor that renders Mermaid.
- Entities — each table becomes an entity block listing column name, type, and a label (
PKfor primary keys,FKfor columns that are referenced by or are foreign keys, blank otherwise). - Relationships — every
FOREIGN KEY ... REFERENCESor inlineREFERENCESclause becomes a relationship line. The cardinality is}o--||(zero-or-more to exactly-one), the standard many-to-one notation for a FK column. - Paste the output into a GitHub README, GitLab wiki, Notion embed block, Obsidian note, or any Markdown environment with Mermaid support. The diagram renders automatically.
What is a Mermaid erDiagram and how is it used in documentation?
Mermaid is a JavaScript-based diagramming library that renders diagrams from plain text definitions embedded in Markdown fenced code blocks. The erDiagram diagram type produces entity-relationship diagrams from a concise syntax: entity blocks list attributes with type and key labels; relationship lines connect entities with cardinality markers. GitHub, GitLab, Notion, Obsidian, and dozens of other tools render Mermaid natively, making it the most portable way to include data model diagrams in code documentation without external diagram files.
The Mermaid ER syntax uses a specific cardinality notation: ||--|| (exactly one to exactly one), ||--o{ (one to zero-or-more), }o--|| (zero-or-more to one). The last pattern — many-to-one — is what a foreign key relationship represents: many rows in the child table reference exactly one row in the parent table. Attribute lines in an entity block have the form type name label where label can be PK, FK, or UK.
Embedding the schema diagram in a repository README means that developers cloning the project immediately see the data model without running the database. Combined with the SQL to DBML Converter for dbdiagram.io, you have two complementary documentation outputs from the same DDL source.
Common use cases
- README documentation — paste the Mermaid block into your project README so the ER diagram renders on GitHub with zero additional tooling.
- Architecture Decision Records — include the schema diagram in an ADR Markdown file to capture the data model at a point in time.
- API documentation — include the entity diagram in an OpenAPI or Markdown API reference to show the underlying data model.
- Pull request reviews — add the diagram to a migration PR description so reviewers see the schema change visually, not just as raw SQL.
- Wiki pages — paste into Notion, Confluence (via Mermaid plugin), or GitLab wiki for living schema documentation that stays in the repo.