Mermaid ER Diagram: Syntax, Examples & Templates

An ER diagram describes a data model — entities, their attributes, and the cardinality of the relationships between them.

Open er diagram in the editor

University enrollment — Mermaid ER Diagram example
University enrollment
Library loans — Mermaid ER Diagram example
Library loans

An ER (entity-relationship) diagram describes the data model of a system: the entities you store, the attributes each one carries, and — most importantly — how many of one entity can be related to how many of another. It is the shared vocabulary between backend engineers, database administrators, and anyone designing migrations.

Basic syntax

erDiagram opens the file. Entities are written in ALL_CAPS by convention, and a relationship line looks like STUDENT ||--o{ ENROLLMENT : makes — left entity, cardinality symbols, right entity, then the relationship verb after a colon. Attributes are declared in a block under the entity name, one per line as type name. The renderer draws entity boxes with their attribute lists and connects them with crow’s-foot notation, so the diagram stays readable even for people who have never seen the syntax.

Relationships and cardinality

The cardinality symbols are the heart of the notation. || means exactly one, o| means zero or one, o{ means zero or more, and |{ means one or more. Reading MEMBER ||--o{ LOAN left to right: one member has zero or more loans, and conversely each loan belongs to exactly one member. Get these wrong and the diagram misleads worse than no diagram, because people trust crow’s feet. A useful check: for each relationship, say the sentence out loud — “one course receives one or more enrollments” — and verify it matches your schema. The verb after the colon should read naturally inside that sentence.

Common gotchas

Attribute types are free text but must be a single word — string, int, date — and attribute names with underscores are fine while spaces are not. Every entity name in a relationship line must be spelled identically everywhere; a typo silently creates a second, empty entity box rather than an error. Do not hide join tables: if ENROLLMENT exists in the database, showing it is honest, and its own attributes (like grade) usually justify the space. Finally, keep attribute lists to the columns that matter for the discussion — a diagram with fifteen attributes per entity is a schema dump, not a design tool.

Tips for mobile editing

Declare the relationship lines first and the attribute blocks second; the relationships are the short, high-value lines you want down before any typing-heavy work on a phone. Keep entity names short and singular. When you add an entity, add its relationship lines at the same time so you never leave a dangling name. The cheatsheet has the full cardinality symbol table.

ER diagrams pair well with class diagrams, which model the same domain one level up in code, and with flowcharts when you need to show the processes that act on the data.

ER Diagram templates

Every template opens in the editor with the code pre-filled — edit it on your phone or desktop.