Database Schema Diagrams

Visualize your database schema with Mermaid ER diagrams. Import SQL CREATE TABLE statements directly or write Mermaid syntax to define entities, attributes, primary keys, foreign keys, and relationships. Perfect for database design, documentation, and migration planning.

Why Use Mermaid

  • Import SQL DDL — Paste CREATE TABLE statements and get an ER diagram instantly
  • Auto-detect relationships — Foreign keys are converted to crow's foot notation
  • Multiple SQL dialects — PostgreSQL, MySQL, SQLite, and SQL Server supported
  • Visual documentation — Generate diagrams for database reviews and onboarding
  • Export anywhere — PNG for docs, SVG for presentations, PDF for printouts

Example Diagram

erDiagram
    USER ||--o{ ORDER : places
    USER ||--o{ ADDRESS : "has"
    ORDER ||--|{ ORDER_ITEM : contains
    ORDER ||--|| PAYMENT : "paid by"
    PRODUCT ||--o{ ORDER_ITEM : "included in"
    CATEGORY ||--o{ PRODUCT : groups

    USER {
        uuid id PK
        string email UK
        string name
        string password_hash
        timestamp created_at
        timestamp updated_at
    }
    ORDER {
        uuid id PK
        uuid user_id FK
        string status
        decimal subtotal
        decimal tax
        decimal total
        timestamp ordered_at
    }
    ORDER_ITEM {
        uuid id PK
        uuid order_id FK
        uuid product_id FK
        int quantity
        decimal unit_price
        decimal line_total
    }
    PRODUCT {
        uuid id PK
        string name
        string sku UK
        decimal price
        int stock
        uuid category_id FK
        text description
    }
    CATEGORY {
        uuid id PK
        string name UK
        uuid parent_id FK
        string slug UK
    }
    ADDRESS {
        uuid id PK
        uuid user_id FK
        string street
        string city
        string state
        string zip
        string country
    }
    PAYMENT {
        uuid id PK
        uuid order_id FK
        string provider
        string transaction_id UK
        decimal amount
        string status
        timestamp paid_at
    }

Copy this code and paste it into the editor to see it rendered live.

Try This Diagram Now

Open the editor with live preview, autocomplete, and export to PNG, SVG, or PDF.

Open Editor

Frequently Asked Questions

More Use Cases