# 2.2. Theory UML ERD¶

• UML - Unified Modeling Language

• ERD - Entity Relationship Diagram

## 2.2.1. Entities vs Attributes¶

• Entities - rows in database

• Attributes - columns in database

## 2.2.2. Cardinality¶

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"

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
}



## 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 ||--o{ ORDER : places
CUSTOMER ||--o{ INVOICE : "liable for"
INVOICE ||--|{ ORDER : covers
ORDER ||--|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||--|{ PRODUCT : contains
PRODUCT ||--o{ ORDER-ITEM : "ordered in"



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