> For the complete documentation index, see [llms.txt](https://wiki.nushackers.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.nushackers.org/orbital/relational-database/index-2.md).

# Entity Relationship Diagram

An **Entity-Relationship Diagram (ERD)** is a visual representation of the relationships between entities in a database. It is a powerful tool used in software development and database design to model and understand the structure of a relational database.

There are many different notations and there is no standard. We are using the **crows-feet** notation. You can build your own ERD in [Lucidchart](https://www.lucidchart.com).

**Let's walk through an example database design problem and visualise it with ERD!**

> Design a system that stores the **users** and their **notebooks**. Each notebook has a *name* and *description*. Each notebook contains several **notes** (but can be empty) and each note has a *title* and *contents*. A user can own multiple notebooks but each notebook belongs to exactly one user, and each note belongs to exactly one notebook. Each user has a *username*, *email*, and *password* that they store.

## Entities

In an Entity-Relationship Diagram (ERD), an entity represents a real-world object or concept. Entities can be classified as either [strong or weak](https://prepinsta.com/dbms/weak-entity-and-strong-entity/).

![ERD 1.0](/files/T1XdMJrcPlaTB10zYFmK)

## Properties

Entities have properties, also known as attributes, which describe their characteristics.

* Primary Key(PK)
* Foreign Key(FK)
* Unique
* ...

![ERD 2.0](/files/7kXY5ub0Pgp8l1e5T7jy)

## Relationships

Relationships represent associations between entities. There are three types of relationships:

* one-to-one (1-1)

  A one-to-one relationship means that each instance of one entity is associated with exactly one instance of another entity.
* many-to-one (M-1)

  A many-to-one relationship means that multiple instances of one entity can be associated with a single instance of another entity.
* many-to-many (M-M)

  A many-to-many relationship means that multiple instances of one entity can be associated with multiple instances of another entity.

#### Crow's feet notation

![Crow's Feet Notation](/files/YcVKV21waBcUneeCqiEA)

## Full ERD

![Full ERD](/files/Joyh1Nc4z7vM8iNDlQj8)

## [Enhanced ERD](https://www.lucidchart.com/pages/enhanced-entity-relationship-diagram)

An enhanced ERD (EERD) extends the capabilities of a traditional ERD by introducing additional concepts such as **specialization/generalization, aggregation, and inheritance**. These concepts allow for more complex modeling of relationships and behaviors in a database system.
