Loading mermaid.tools…

Entity relationship editor for database schemas

Document entities, fields, keys, and their cardinalities in Mermaid source that can live next to your schema.

An ER diagram documents the shape of stored data. Use a class diagram instead when you are describing behaviour and inheritance rather than tables and keys.

How to make an ER diagram online

  1. List the entities before the relationships, so the diagram grows out of the tables you already have.
  2. Connect two entities with the cardinality markers that match reality: optional or required, one or many, on each side.
  3. Open an entity block and add its fields with their types, marking primary and foreign keys as PK and FK.
  4. Keep the Mermaid source beside your migrations so the diagram can be regenerated whenever the schema changes.
Mermaid er diagram: Order data model. Edit this order data model in Mermaid, inspect the rendered result, and adapt the working source for your own documentation.
Order data model — the starter this page opens with. See the full example.

ER diagram syntax cheat sheet

What it doesSyntaxNotes
StarterDiagramSelects entity-relationship syntax.
One to manyCUSTOMER ||--o{ ORDER : placesOne customer places zero or more orders.
Required manyORDER ||--|{ ITEM : containsOne order requires at least one item.
Entity blockCUSTOMER { ... }Opens the field list for an entity.
Primary keyint id PKMarks a field as the primary key.
Foreign keyint customer_id FKMarks a field as a foreign key.

Editable ER diagram examples

All ER diagram examples · the whole example library

Frequently asked questions

Can Mermaid ER diagrams show primary and foreign keys?

Yes. Add PK after a field name for a primary key and FK for a foreign key, inside the entity block.

How do I show one-to-many cardinality?

Use the marker pair that matches optionality and count on each side, such as ||--o{ for one to zero-or-more.

Should I keep the diagram or the image as the original?

Keep the Mermaid source as the editable original and regenerate the SVG after each schema change; an exported image cannot be diffed in review.

Keep reading

Fix diagram errors · Export formats · all guides

mermaid.tools is an independent editor not affiliated with the Mermaid.js project or Mermaid Chart / mermaid.ai. Diagrams render in your browser with Mermaid 11.17.2.