Skip to content

Entity Relationship Diagram

Entity Relationship (ER) diagrams document database structures and the relationships between tables. Mermaid Studio provides full language support for designing and maintaining your data models.

erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : "ordered in"
CUSTOMER {
int id PK
string name
string email
}
ORDER {
int id PK
date created
int customer_id FK
}

ER diagrams have comprehensive IDE support:

  • Syntax highlighting - Distinct colors for entities, attributes, and relationships
  • Code completion - Suggestions for relationship types and attribute modifiers
  • Refactoring - Rename entities and update all references
  • Find usages - See where entities are referenced in relationships
  • Code Vision - Inline hints showing relationship counts
  • Navigation bar - Quick access to entities in large schemas
  • Code folding - Collapse entity definitions
  • Formatting - Auto-format your diagram code
  • Inspections - Detect undefined entities and invalid relationships

Relationship cardinality:

  • || - Exactly one
  • o| - Zero or one
  • }| - One or more
  • o{ - Zero or more

Common patterns:

  • ||--o{ - One to many (optional)
  • ||--|{ - One to many (required)
  • }o--o{ - Many to many

Entity attributes:

erDiagram
USER {
int id PK
string email UK
int role_id FK
string name
}

Attribute modifiers: PK (primary key), FK (foreign key), UK (unique key)

For the complete syntax reference, see the Mermaid.js ER Diagram documentation.