cheatsheet / current

Entity Relationship Diagram

Use Mermaid erDiagram to model tables, entities, fields, keys, and cardinality.

Entity Relationship Diagram

Use Mermaid erDiagram to model tables, entities, fields, keys, and cardinality.

Basic template

erDiagram
    CUSTOMER ||--o{ ORDER : places
    CUSTOMER {
        string CustomerID PK
        string Name
    }

Core syntax

  • Start with erDiagram
  • Define relationships like A ||--o{ B : label
  • Common cardinality markers:
    • || exactly one
    • o| zero or one
    • |{ one or many
    • o{ zero or many
  • Add fields inside entity blocks
  • Mark key columns with labels like PK and FK

Common example

erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ ORDER_LINE : contains
    PRODUCT ||--o{ ORDER_LINE : appears_on

    CUSTOMER {
        string CustomerID PK
        string Name
        string Email
    }

    ORDER {
        string OrderID PK
        date OrderDate
        string CustomerID FK
    }

    ORDER_LINE {
        string OrderLineID PK
        string OrderID FK
        string ProductID FK
        int Quantity
    }

    PRODUCT {
        string ProductID PK
        string Name
        decimal Price
    }

Good for

  • Database design
  • Data integration mapping
  • System documentation

Watch for

  • Keep naming consistent with the actual schema
  • Mermaid ER diagrams are ideal for conceptual and logical models, not every physical storage detail