Blog
Wild & Free Tools

ER Diagram Examples and Templates — Ready-to-Use ERD Code

Last updated: April 3, 2026 8 min read

Table of Contents

  1. E-Commerce Database ERD
  2. Blog and CMS Database ERD
  3. Library Management System ERD
  4. Hospital Management System ERD
  5. HR and Employee Management ERD
  6. How to Customize These Templates
  7. Frequently Asked Questions

Rather than building an ER diagram from scratch, start from a working template for your use case. This guide provides copy-paste Mermaid erDiagram code for five common database schemas — e-commerce, blog/CMS, library management, hospital management, and HR system. Each example is ready to paste into the free ERD maker (or any Mermaid renderer) and renders immediately.

E-Commerce Database ERD

A standard e-commerce database covering customers, products, orders, and shipping:

erDiagram
    CUSTOMERS {
        int id PK
        string first_name
        string last_name
        string email
        string phone
        datetime created_at
    }
    PRODUCTS {
        int id PK
        string name
        text description
        decimal price
        int stock_qty
        int category_id FK
    }
    CATEGORIES {
        int id PK
        string name
        int parent_id FK
    }
    ORDERS {
        int id PK
        int customer_id FK
        decimal subtotal
        decimal tax
        decimal shipping
        decimal total
        string status
        datetime ordered_at
    }
    ORDER_ITEMS {
        int id PK
        int order_id FK
        int product_id FK
        int quantity
        decimal unit_price
    }
    ADDRESSES {
        int id PK
        int customer_id FK
        string street
        string city
        string state
        string country
        string postal_code
        boolean is_default
    }
    SHIPMENTS {
        int id PK
        int order_id FK
        int address_id FK
        string carrier
        string tracking_number
        datetime shipped_at
        datetime delivered_at
    }

    CUSTOMERS ||--o{ ORDERS : "places"
    CUSTOMERS ||--o{ ADDRESSES : "has"
    ORDERS ||--|{ ORDER_ITEMS : "contains"
    ORDERS ||--|| SHIPMENTS : "shipped via"
    SHIPMENTS ||--|| ADDRESSES : "delivered to"
    PRODUCTS ||--o{ ORDER_ITEMS : "included in"
    CATEGORIES ||--o{ PRODUCTS : "contains"
    CATEGORIES ||--o{ CATEGORIES : "subcategory of"

Blog and CMS Database ERD

A content management system schema covering posts, authors, categories, tags, and comments:

erDiagram
    USERS {
        int id PK
        string username
        string email
        string password_hash
        string role
        datetime created_at
    }
    POSTS {
        int id PK
        int author_id FK
        string title
        string slug
        text content
        string status
        datetime published_at
        datetime created_at
    }
    CATEGORIES {
        int id PK
        string name
        string slug
        int parent_id FK
    }
    TAGS {
        int id PK
        string name
        string slug
    }
    POST_TAGS {
        int post_id FK
        int tag_id FK
    }
    POST_CATEGORIES {
        int post_id FK
        int category_id FK
    }
    COMMENTS {
        int id PK
        int post_id FK
        int user_id FK
        text body
        int parent_id FK
        datetime created_at
    }
    MEDIA {
        int id PK
        int uploaded_by FK
        string filename
        string file_type
        string url
        datetime created_at
    }

    USERS ||--o{ POSTS : "writes"
    USERS ||--o{ COMMENTS : "writes"
    POSTS ||--o{ COMMENTS : "has"
    POSTS ||--o{ POST_TAGS : "tagged with"
    POSTS ||--o{ POST_CATEGORIES : "categorized in"
    TAGS ||--o{ POST_TAGS : "applied to"
    CATEGORIES ||--o{ POST_CATEGORIES : "applied to"
    COMMENTS ||--o{ COMMENTS : "replies to"
    USERS ||--o{ MEDIA : "uploads"

Library Management System ERD

A library system covering books, members, borrowing, and fines — a classic database assignment schema:

erDiagram
    MEMBERS {
        int id PK
        string first_name
        string last_name
        string email
        string phone
        string membership_type
        date membership_expiry
        datetime joined_at
    }
    BOOKS {
        int id PK
        string isbn
        string title
        int author_id FK
        int publisher_id FK
        int genre_id FK
        int total_copies
        int available_copies
        date published_date
    }
    AUTHORS {
        int id PK
        string name
        string nationality
        date birth_date
    }
    PUBLISHERS {
        int id PK
        string name
        string country
    }
    GENRES {
        int id PK
        string name
    }
    LOANS {
        int id PK
        int member_id FK
        int book_copy_id FK
        date loan_date
        date due_date
        date returned_date
        string status
    }
    BOOK_COPIES {
        int id PK
        int book_id FK
        string condition
        string location
    }
    FINES {
        int id PK
        int loan_id FK
        decimal amount
        boolean is_paid
        datetime created_at
    }

    MEMBERS ||--o{ LOANS : "borrows"
    LOANS ||--|| BOOK_COPIES : "of"
    BOOK_COPIES ||--|| BOOKS : "copy of"
    BOOKS ||--|| AUTHORS : "written by"
    BOOKS ||--|| PUBLISHERS : "published by"
    BOOKS ||--|| GENRES : "categorized as"
    LOANS ||--o{ FINES : "incurs"
Sell Custom Apparel — We Handle Printing & Free Shipping

Hospital Management System ERD

A simplified hospital system covering patients, doctors, appointments, and medical records:

erDiagram
    PATIENTS {
        int id PK
        string first_name
        string last_name
        date date_of_birth
        string blood_type
        string phone
        string email
        datetime registered_at
    }
    DOCTORS {
        int id PK
        string first_name
        string last_name
        int department_id FK
        string specialization
        string license_number
        string phone
    }
    DEPARTMENTS {
        int id PK
        string name
        string floor
        string phone
    }
    APPOINTMENTS {
        int id PK
        int patient_id FK
        int doctor_id FK
        datetime scheduled_at
        string status
        text notes
    }
    MEDICAL_RECORDS {
        int id PK
        int patient_id FK
        int doctor_id FK
        date visit_date
        text diagnosis
        text prescription
        text notes
    }
    PRESCRIPTIONS {
        int id PK
        int record_id FK
        string medication
        string dosage
        int duration_days
    }

    PATIENTS ||--o{ APPOINTMENTS : "schedules"
    DOCTORS ||--o{ APPOINTMENTS : "attends"
    DOCTORS ||--|| DEPARTMENTS : "belongs to"
    PATIENTS ||--o{ MEDICAL_RECORDS : "has"
    DOCTORS ||--o{ MEDICAL_RECORDS : "creates"
    MEDICAL_RECORDS ||--o{ PRESCRIPTIONS : "includes"

HR and Employee Management ERD

A human resources system covering employees, departments, payroll, and leave management:

erDiagram
    EMPLOYEES {
        int id PK
        string first_name
        string last_name
        string email
        string phone
        int department_id FK
        int manager_id FK
        int job_id FK
        decimal salary
        date hire_date
        string employment_type
    }
    DEPARTMENTS {
        int id PK
        string name
        int manager_id FK
        string location
    }
    JOBS {
        int id PK
        string title
        decimal min_salary
        decimal max_salary
    }
    PAYROLL {
        int id PK
        int employee_id FK
        string pay_period
        decimal gross_pay
        decimal deductions
        decimal net_pay
        date paid_on
    }
    LEAVE_REQUESTS {
        int id PK
        int employee_id FK
        int approver_id FK
        string leave_type
        date start_date
        date end_date
        string status
        text reason
    }
    PERFORMANCE_REVIEWS {
        int id PK
        int employee_id FK
        int reviewer_id FK
        int review_year
        int quarter
        int rating
        text comments
    }

    EMPLOYEES ||--|| DEPARTMENTS : "assigned to"
    EMPLOYEES ||--|| JOBS : "holds"
    EMPLOYEES ||--o{ EMPLOYEES : "managed by"
    DEPARTMENTS ||--|| EMPLOYEES : "managed by"
    EMPLOYEES ||--o{ PAYROLL : "receives"
    EMPLOYEES ||--o{ LEAVE_REQUESTS : "submits"
    EMPLOYEES ||--o{ PERFORMANCE_REVIEWS : "reviewed in"

How to Customize These Templates

All five examples use Mermaid erDiagram syntax and render in the free ERD maker without modification. To adapt them for your project:

  1. Rename entities: Change entity names (CUSTOMERS, ORDERS, etc.) to match your actual table names. Use consistent naming — either all-caps or CamelCase.
  2. Add or remove columns: Each attribute line is datatype column_name OPTIONAL_KEY. Remove columns you do not need or add new ones below the last existing line in the block.
  3. Change relationship labels: The quoted text after the colon in relationship lines is just a label. Change it to anything descriptive.
  4. Adjust relationship cardinality: Change ||--o{ to ||--|| for one-to-one, or }o--o{ for many-to-many, as your schema requires.
  5. Export and embed: Export as PNG for documentation or SVG for scalable use. The Mermaid code itself can go in your README or Notion page for live rendering.

Open the Free ERD Maker and Paste Your Template

Copy any template above, paste into the ERD code editor, click Render. Free, no signup.

Open Free ERD Maker

Frequently Asked Questions

Can I use these ERD templates for university database assignments?

Yes. These templates are in Mermaid erDiagram syntax, which renders crow's foot notation. If your assignment requires a specific notation (like Chen notation with diamonds), these templates will not match that requirement — use ERDPlus instead, which supports Chen notation. For crow's foot notation assignments, paste any of these templates into the free ERD maker and export the PNG to attach to your submission.

How do I add more relationship types to these examples?

Add a new line below the existing relationships following the pattern: ENTITY_ONE NOTATION ENTITY_TWO : "label". Notation options are ||--|| (one-to-one), ||--o{ (one to zero-or-more), ||--|{ (one to one-or-more), }o--o{ (many-to-many optional), and }|--|{ (many-to-many required).

Can I import these ERD templates into dbdiagram.io?

Not directly — dbdiagram.io uses DBML syntax, which is different from Mermaid erDiagram syntax. However, the structure is similar: convert each entity block to a Table block in DBML, and convert relationship lines to Ref statements. The WildandFree ERD maker uses Mermaid, which renders directly in GitHub READMEs and Notion without any separate tool.

What is the difference between PK and FK in these examples?

PK stands for Primary Key — the unique identifier for each row in the table. FK stands for Foreign Key — a column that references the Primary Key of another table to establish a relationship. In the Mermaid erDiagram syntax, PK and FK are display labels only — they appear in the diagram to identify key columns but do not enforce constraints (constraints are enforced by the actual database, not the diagram tool).

Stephanie Ward
Stephanie Ward Diagram & Visual Documentation Writer

Stephanie spent eight years as a business analyst creating flowcharts, ERDs, and process diagrams for enterprise software teams. She makes diagram creation approachable for teams without a dedicated designer.

More articles by Stephanie →
Launch Your Own Clothing Brand — No Inventory, No Risk