> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/system-design/system-design-methodology/diagrams/uml-diagrams/plantuml/er-diagram-entity-relationship.md).

# ER Diagram (Entity-Relationship)

## About

An ER Diagram represents data models and relationships between entities in a database. It is widely used in database design and schema planning.

{% hint style="success" %}
Refer to the official documentation for more details - <https://plantuml.com/er-diagram>
{% endhint %}

{% content-ref url="/pages/45bclIZBVrOBtVlTGEod" %}
[Entity Relationship Diagram (ERD)](/the-programmers-guide/database/sql-databases/rdbms/entity-relationship-diagram-erd.md)
{% endcontent-ref %}

### **Key Elements**

1. **Entities**
   * Represented as **rectangles**, denoting **real-world objects** (e.g., `Customer`, `Order`).
2. **Attributes**
   * Represented as **ellipses** connected to entities.
   * **Primary Key (PK)** – Unique identifier (underlined).
   * **Foreign Key (FK)** – Connects to another entity.
3. **Relationships**
   * Represented as **diamonds** between entities (e.g., `Places Order`).
   * **1:1, 1:M, M:N** relationships specify cardinality.
4. **Cardinality & Participation**
   * **(1,1), (0,N), (M,N)** define relationship constraints.

## 1. **Employee Management System**

This represents **database entities and relationships** for an **Employee Management System**.

{% hint style="success" %}

* **Entities (`entity Name { }`)**.
* **Primary Keys (`* field : type`)**.
* **Relationships (`}|..||`)**.
  {% endhint %}

```java
@startuml
title Employee Management - ER Diagram

entity Employee {
    * emp_id : INT
    --
    name : STRING
    age : INT
    department_id : INT
}

entity Department {
    * dept_id : INT
    --
    dept_name : STRING
}

Employee }|..|| Department : belongs_to

@enduml
```

<figure><img src="/files/xyshSxdpE5X1fe9C6QXO" alt="" width="245"><figcaption></figcaption></figure>

## 2. Order System

This represents **tables and their foreign key constraints**.

```plant-uml
@startuml
title Database Schema - Order System

entity Customers {
    * id : INT
    --
    name : STRING
    email : STRING
}

entity Orders {
    * id : INT
    --
    customer_id : INT
    total_amount : DECIMAL
}

entity Order_Items {
    * id : INT
    --
    order_id : INT
    product_id : INT
    quantity : INT
}

Customers ||--|{ Orders : has
Orders ||--|{ Order_Items : contains

@enduml
```

<figure><img src="/files/3REUNBG3D0PncVHBhNvz" alt="" width="227"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/system-design/system-design-methodology/diagrams/uml-diagrams/plantuml/er-diagram-entity-relationship.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
