merIDK / Diagram types / ER diagram
Mermaid ER diagram: example and syntax
Entity relationship diagrams describe a database schema: tables, their columns and keys, and how tables relate. Use them to plan a schema or document an existing one.
Open this example in the editor
Example code
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : "ordered in"
CUSTOMER {
int id PK
string name
string email UK
}
ORDER {
int id PK
int customer_id FK
date created_at
}
PRODUCT {
int id PK
string sku
decimal price
}
Result
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : "ordered in"
CUSTOMER {
int id PK
string name
string email UK
}
ORDER {
int id PK
int customer_id FK
date created_at
}
PRODUCT {
int id PK
string sku
decimal price
}Syntax quick reference
- Cardinality marks:
||exactly one,o|zero or one,}ozero or more,}|one or more. - Example:
CUSTOMER ||--o{ ORDER : places. - Columns go in braces:
int id PK,int user_id FK,string email UK.
How to use it
- Open the example in the editor, or paste your own Mermaid code.
- Edit the code on the left. The preview updates as you type, and errors point to the line.
- Export SVG or PNG, copy a Markdown block for GitHub or Notion, or copy a share link.