> 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="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2FfiBLuks8KRAz5DEO4AdM%2Fplantuml-er-diagram-1.png?alt=media&amp;token=bff70377-bb4a-40a6-aecc-b1887f08d8d5" 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="https://3632859567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPd6ktrA5pPLsZJktj2fm%2Fuploads%2F9WisdUcHmZCSXTKUc4Ba%2Fplantuml-er-diagram-2.png?alt=media&amp;token=edf83d13-adad-447c-88fc-1b677f41ca5d" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
