# Entity Relationship Diagrams

### What are Entity Relationship Diagrams?

Mermaid's Entity Relationship Diagrams (ERDs) help you visualize database structures and relationships. For analytics engineers, they're essential for documenting data models, table relationships, and database schemas. ERDs show how different entities (tables) in your database relate to each other, including their attributes and the nature of their relationships.

***

### Creating Your First ERD

1. **Launch DinoAI:** From Code IDE, access [DinoAI](https://docs.paradime.io/app-help/documentation/dino-ai) to start creating diagrams.
2. **Use a Simple Prompt:** Tell DinoAI what kind of ERD you want to create. For example:

{% code overflow="wrap" %}

```
- "Create a mermaid  ERD diagram showing the relationships between my customer, order, and product tables"

- "Generate a mermaid ERD for my e-commerce data model with proper cardinality notation"

- "Build a mermaid ERD diagram for my dbt models showing table relationships and key columns"
```

{% endcode %}

3. **Get Your Diagram:** DinoAI will generate a complete `.mmd` file with proper Mermaid syntax.
4. **Preview Your Work:** Click the eye icon (👁️) to preview your diagram in real-time as you edit.
5. **Iterate and Refine:** Modify the generated `.mmd` file directly, or ask DinoAI to make specific changes.

#### Example

{% code title=".mmd file" %}

```mermaid
---
title: Order example
---
erDiagram
    CUSTOMER ||--o{ ORDER : places
    ORDER ||--|{ LINE-ITEM : contains
    CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
```

{% endcode %}

<figure><img src="https://2337193041-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHET0AD04uHMgdeLAjptq%2Fuploads%2Fs9q5EoS8yC9AtHA3sfHv%2Fimage.png?alt=media&#x26;token=e33cf92b-79d3-4721-9d24-757e0cbda904" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

#### Reusable ERD prompts for you and your team

You can create custom, standardized [.dinoprompts](https://docs.paradime.io/app-help/documentation/dino-ai/dino-prompts) for Mermaid's ERDiagrams that ensure consistency across your data team. See [step-by-step guide.](https://docs.paradime.io/app-help/documentation/integrations/code-ide/mermaid-js/..#creating-mermaid-diagrams-with-.dinoprompts)
{% endhint %}

***

### Diagram Syntax Guide

#### Basic Entity Definition

```mermaid
erDiagram
    FACT_TABLE {
        string order_id PK
        timestamp created_at
        decimal amount
    }
```

#### Cardinality Notation

Show relationships between entities using crow's foot notation:

* `||--||` : Exactly one to exactly one
* `||--o{` : One to many (zero or more)
* `||--|{` : One to many (one or more)
* `}o--o{` : Many to many

#### Relationship Types

* Solid lines (--): Identifying relationship
* Dotted lines (..): Non-identifying relationship

***

{% hint style="success" %}

#### Best Practices

1. Use clear, descriptive entity names
2. Show only relevant attributes
3. Include key relationships
4. Use consistent naming conventions
5. Document primary and foreign keys
6. Group related entities together
   {% endhint %}

{% hint style="info" %}

### Additional Resources

For more syntax options and advanced features, visit the [official Mermaid documentation](https://mermaid.js.org/syntax/entityRelationshipDiagram.html)
{% endhint %}
