ER Diagram Online Editor
Create entity relationship diagrams online with Mermaid: tables, keys, attributes and crow’s foot cardinality, with live preview and free PNG, SVG or PDF export.
Try it
Edit the code; the preview updates as you type.
Rendering diagram…
What is an ER diagram?
An entity relationship (ER) diagram shows the tables or entities in a data model and how they relate: one-to-one, one-to-many or many-to-many. Mermaid draws the relationships with crow’s foot notation.
Write erDiagram on the first line, then one relationship per line. Attributes, primary keys and foreign keys go in a block after the entity name, so the diagram doubles as lightweight schema documentation.
When to use it
- Sketching a database schema before writing migrations
- Documenting an existing schema in a README or wiki
- Reviewing foreign keys and cardinality in a pull request
- Explaining a domain model to non-developers
- Teaching normalization and relational design
Mermaid ER diagram syntax
Every diagram of this type starts with erDiagram.
| Syntax | Meaning |
|---|---|
A ||--o{ B : label | One A has zero or more B. The label after the colon is required. |
|| | Exactly one. |
|o / o| | Zero or one. |
}o / o{ | Zero or more. |
}| / |{ | One or more. |
-- vs .. | A solid line is an identifying relationship; a dotted line is non-identifying. |
ENTITY { type name } | Lists attributes, one per line, as type then name. |
PK, FK, UK | Marks primary, foreign and unique keys after the attribute name; combine as PK, FK. |
type name "comment" | Adds a quoted comment to an attribute. |
More examples
Many-to-many through a join table
erDiagram
STUDENT ||--o{ ENROLLMENT : has
COURSE ||--o{ ENROLLMENT : includes
ENROLLMENT {
int student_id FK
int course_id FK
string grade
}Common mistakes and how to fix them
- A relationship line has no label, for example A ||--o{ B.
- Add a colon and a label: A ||--o{ B : has. Use "" for an empty label.
- An attribute type contains spaces or brackets, such as varchar(255).
- Use a single word like varchar or string, and put the length in a quoted comment.
- An entity name contains spaces.
- Join the words with underscores or hyphens, for example ORDER_ITEM or order-item.
Export your ER diagram
Download a PNG, SVG or PDF straight from the playground above. For more options, such as a 1x to 4x scale, a transparent background or copying the image, choose Open in editor and use the Export menu there. Export is free, needs no account and adds no watermark.
Frequently asked questions
Which ER notation does Mermaid use?
Crow’s foot notation. The two characters at each end of a relationship describe the minimum and maximum: | means one, o means zero and { or } means many.
How do I mark a primary key or foreign key?
Write PK, FK or UK after the attribute name inside the entity block, for example int customer_id FK. Several keys can be combined with commas.
Can I generate a Mermaid ER diagram from SQL?
Mermaid does not read SQL directly. You can paste your CREATE TABLE statements into the optional AI assistant with your own API key and ask for an erDiagram, then review the result in the preview.
Does GitHub render Mermaid ER diagrams?
Yes. Paste the code into a ```mermaid code block in a GitHub issue, pull request or Markdown file. Export a PNG or SVG here for tools that do not render Mermaid.