Mermaid ER Diagram
Database schemas as text, rendered in your Markdown docs
A Mermaid ER diagram (entity relationship diagram) shows database tables and how they relate, using crow’s foot notation. It is a quick way to document a schema in a README or a design doc — and it renders in GitHub, GitLab, Obsidian and MDViewer.
Entities and Relationships
Start with erDiagram. Each line connects two entities, describes the cardinality on both ends, and adds a label after the colon:
Read CUSTOMER ||--o{ ORDER : places as “one customer places zero or more orders”. Labels with spaces need quotes.
Cardinality (Crow’s Foot)
Each end of the line uses two characters. On the left side the outer character comes first; on the right side it is mirrored:
| Left | Right | Meaning |
|---|---|---|
|o | o| | Zero or one |
|| | || | Exactly one |
}o | o{ | Zero or more |
}| | |{ | One or more |
The middle of the line sets the relationship type: -- (solid) is identifying — the child cannot exist without the parent; .. (dashed) is non-identifying.
Attributes and Keys
Add a block after the entity name with one attribute per line: type, name and an optional key — PK, FK or UK (unique):
Types are free text, so use whatever your database calls them (varchar, uuid, timestamp…). A quoted string after the key adds a comment.
Tips
- Name entities in UPPER_SNAKE_CASE or singular nouns — it keeps the diagram readable.
- Document only the columns that explain the relationships; a full schema dump belongs in a migration, not a diagram.
- For classes and methods rather than tables, use a class diagram.
More Mermaid guides: What is Mermaid, flowcharts, sequence diagrams, timelines, Gantt charts, class diagrams, ER diagrams and pie charts. To open .mmd files on a Mac, see how to open Mermaid files.
FAQ
How do I create an ER diagram in Markdown?
Add a fenced code block with the language mermaid, start it with erDiagram and write one relationship per line, for example CUSTOMER ||--o{ ORDER : places.
What does ||--o{ mean in Mermaid?
|| means exactly one and o{ means zero or more: one record on the left relates to zero or more records on the right, joined by an identifying (solid) line.
How do I mark primary and foreign keys in a Mermaid ER diagram?
Add PK, FK or UK after the attribute name inside the entity block, for example int customer_id FK.
Does GitHub render Mermaid ER diagrams?
Yes. GitHub renders erDiagram code blocks in Markdown files, issues and pull requests.
View It with MDViewer
MDViewer renders Mermaid diagrams inside any .md file on your Mac — click a diagram to zoom and pan. Paste an example from this guide into a file and open it, or try it without installing in the free online viewer.
Lite is free for personal use; Pro is $9.99 one-time. Requires macOS 13.0 or later, Intel and Apple Silicon.