Entity Relationship Diagrams

What are Entity Relationship Diagrams?

Mermaid's Entity Relationship Diagrams (ERDs) help you visualize database structures and relationships. For analytics engineers, they're essential for documenting data models, table relationships, and database schemas. ERDs show how different entities (tables) in your database relate to each other, including their attributes and the nature of their relationships.

Creating Your First ERD

  1. From the Code IDE, Click Apps and Agents from the lefthand panel

  2. Select Mermaid. Paradime will automatically start a new mermaid project

  3. In the terminal that appears, use the arrow keys to select "Entity Relationship Diagrams"

  4. A new entityRelationshipDiagram.mmd file will be created in your editor with this starter template:

---
title: Order example
---
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE-ITEM : contains
    CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
  1. Click the eye icon (👁️) in the top right corner of your Mermaid file to preview the diagram

  2. Edit and update your .mmd file as needed - the preview will update automatically

Diagram Syntax Guide

Basic Entity Definition

erDiagram
    FACT_TABLE {
        string order_id PK
        timestamp created_at
        decimal amount
    }

Cardinality Notation

Show relationships between entities using crow's foot notation:

  • ||--|| : Exactly one to exactly one

  • ||--o{ : One to many (zero or more)

  • ||--|{ : One to many (one or more)

  • }o--o{ : Many to many

Relationship Types

  • Solid lines (--): Identifying relationship

  • Dotted lines (..): Non-identifying relationship

Data Team Examples

Star Schema

erDiagram
    DIM_CUSTOMER ||--o{ FACT_SALES : generates
    DIM_PRODUCT ||--o{ FACT_SALES : includes
    DIM_DATE ||--o{ FACT_SALES : occurs_on

    FACT_SALES {
        string sale_id PK
        string customer_id FK
        string product_id FK
        date sale_date FK
        decimal amount
    }

    DIM_CUSTOMER {
        string customer_id PK
        string name
        string segment
    }

Data Pipeline Tables

erDiagram
    STG_ORDERS ||--|{ STG_ORDER_ITEMS : contains
    INT_ORDERS }|--|| FCT_SALES : transforms_to
    
    STG_ORDERS {
        string order_id PK
        timestamp created_at
        string status
    }

Best Practices

  1. Use clear, descriptive entity names

  2. Show only relevant attributes

  3. Include key relationships

  4. Use consistent naming conventions

  5. Document primary and foreign keys

  6. Group related entities together

Additional Resources

For more syntax options and advanced features, visit the official Mermaid documentation

Last updated

Was this helpful?