# 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](https://2807223923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUqAJOgHs57S8lmqdxRV%2Fuploads%2Fgit-blob-e1b1f3b723ab3b88f2a7a99f9c38589b27cca34e%2Fimage.png?alt=media)

## Properties

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

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

![ERD 2.0](https://2807223923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUqAJOgHs57S8lmqdxRV%2Fuploads%2Fgit-blob-83750c07be9db5cb8ba5bfc8d0f72e0a608aba28%2Fimage-2.png?alt=media)

## 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](https://2807223923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUqAJOgHs57S8lmqdxRV%2Fuploads%2Fgit-blob-5ceadb9ded732b63d8aed1e2935d233072580f8c%2Fimage-3.png?alt=media)

## Full ERD

![Full ERD](https://2807223923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUqAJOgHs57S8lmqdxRV%2Fuploads%2Fgit-blob-6867874b2acf32f3d7ceca2db7acfbc61bff7727%2Fimage-4.png?alt=media)

## [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.


---

# Agent Instructions: 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:

```
GET https://wiki.nushackers.org/orbital/relational-database/index-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
