2.2. Theory UML ERD

  • UML - Unified Modeling Language

  • ERD - Entity Relationship Diagram

../../_images/uml-erd-1.png
../../_images/uml-erd-2.png

2.2.1. Entities vs Attributes

  • Entities - rows in database

  • Attributes - columns in database

../../_images/uml-erd-entities,attributes.png

2.2.2. Cardinality

../../_images/uml-erd-cardinality.png

Cardinality:

Table 2.1. Cardinality

left

right

description

|o

o|

zero or one

||

||

exactly one

}o

o{

zero or more (no upper limit)

}|

|{

one or more (no upper limit)

Relationship:

Table 2.2. Cardinality

cardinality

relationship

||..||

one to one

||..|{

one to many

}|..||

many to one

}|..|{

many to many

2.2.3. Entity Relationship Diagram

  • ERD - Entity Relationship Diagram 4

  • By drawing a line between tables we show, that there is a connection between them in some way

  • English: "crows foot notation"

  • Polish: "notacja kurzych stóp"

../../_images/uml-erd-astronaut,assignment,mission,role.png

Right:

  • ASSIGNMENT relates to one MISSION

  • ASSIGNMENT assigns one ASTRONAUT

  • ASSIGNMENT defines one ROLE

Left:

  • MISSION is related to zero or many ASSIGNMENT

  • ASTRONAUT is assigned to zero or many ASSIGNMENT

  • ROLE is defined in one ASSIGNMENT

```mermaid
erDiagram

ASSIGNMENT }o..|| MISSION : "relates to"
ASSIGNMENT }o..|| ASTRONAUT : "assigns"
ASSIGNMENT ||..|| ROLE : "defines"

ASSIGNMENT {
    primary_key id
    foreign_key mission_id
    foreign_key astronaut_id
    str role
}

ROLE {
    primary_key id
    str name
}

ASTRONAUT {
    primary_key id
    str firstName
    str lastName
    int age
}

MISSION {
    primary_key id
    int year
    int name
}
```
../../_images/uml-erd-export.png

2.2.4. Mermaid

  • mermaid - Markdown extension 1

Theming 2:

%%{init: { 'theme': 'dark' } }%%
%%{init: { 'theme': 'forest' } }%%

Config 3:

%%{init: { 'logLevel': 'debug' } }%%
%%{config: { 'fontFamily': 'Menlo', 'fontSize': 18, 'fontWeight': 400} }%%
Table 2.3. CSS classes

Selector

Description

.er.attributeBoxEven

The box containing attributes on even-numbered rows

.er.attributeBoxOdd

The box containing attributes on odd-numbered rows

.er.entityBox

The box representing an entity

.er.entityLabel

The label for an entity

.er.relationshipLabel

The label for a relationship

.er.relationshipLabelBox

The box surrounding a relationship label

.er.relationshipLine

The line representing a relationship between entities

2.2.5. Use Case - 0x01

```mermaid
erDiagram

CUSTOMER }|..|{ DELIVERY-ADDRESS : has
CUSTOMER ||--o{ ORDER : places
CUSTOMER ||--o{ INVOICE : "liable for"
DELIVERY-ADDRESS ||--o{ ORDER : receives
INVOICE ||--|{ ORDER : covers
ORDER ||--|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||--|{ PRODUCT : contains
PRODUCT ||--o{ ORDER-ITEM : "ordered in"
```
../../_images/uml-erd-mermaid-usecase1.png

2.2.6. Use Case - 0x02

../../_images/uml-erd-3.png
../../_images/uml-erd-4.jpg
../../_images/uml-erd-5.png
../../_images/uml-erd-6.jpg

2.2.7. References

1

Sveidqvist, Knut et al. Mermaid Documentation: About. Year: 2022. Retrieved: 2022-01-26. URL: https://mermaid-js.github.io/mermaid/#/README

2

Sveidqvist, Knut et al. Mermaid Documentation: Theming. Year: 2022. Retrieved: 2022-01-26. URL: https://mermaid-js.github.io/mermaid/#/theming

3

Sveidqvist, Knut et al. Mermaid Documentation: SyntaxReference. Year: 2022. Retrieved: 2022-01-26. URL: https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference

4

Sveidqvist, Knut et al. Mermaid Documentation: Entity Relationship Diagrams. Year: 2022. Retrieved: 2022-01-26. URL: https://mermaid-js.github.io/mermaid/#/entityRelationshipDiagram