Diagrams / Mermaid ER Diagram: Syntax & Examples
Mermaid ER Diagram: Syntax & Examples
Explore Mermaid ER syntax with entities, key markers and cardinality. Read a customer-order example, then edit and preview the data model.
When to use ER Diagram
Describe an entity relationship model with Mermaid ER syntax. This view helps readers understand entities, attributes, and how records can relate. Use it for conceptual data design or a physical schema review, and make clear which level the diagram represents.
Read the ER Diagram example
Diagram source
erDiagram
CUSTOMER ||..o{ ORDER : places
ORDER ||--|{ ORDER_ITEM : contains
CUSTOMER {
int id PK
string name
}
ORDER {
int id PK
int customer_id FK
}
ORDER_ITEM {
int order_id PK,FK
int line_number PK
int quantity
}How to use this tool
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Cardinality | Crow’s foot markers describe one or many instances, while optionality distinguishes zero from a required instance. |
| Keys | PK, FK, and UK can mark primary, foreign, and unique keys. Include them when implementation detail helps the reader. |
| Relationship style | Solid and dashed lines distinguish identifying and non-identifying relationships. They are semantic choices, not decoration. |
Common questions
Can the diagram enforce database constraints?
No. It documents the model. Verify keys, nullability, and constraints in the actual schema; an attractive diagram does not prove data integrity.