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%2Cattributes.png

2.2.2. Cardinality

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

Cardinality:

Table 2.5. 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.6. 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%2Cassignment%2Cmission%2Crole.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.7. 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