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:
left |
right |
description |
---|---|---|
|
|
zero or one |
|
|
exactly one |
|
|
zero or more (no upper limit) |
|
|
one or more (no upper limit) |
Relationship:
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 toone MISSION
ASSIGNMENT
assignsone ASTRONAUT
ASSIGNMENT
definesone ROLE
Left:
MISSION
is related tozero or many ASSIGNMENT
ASTRONAUT
is assigned tozero or many ASSIGNMENT
ROLE
is defined inone 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} }%%
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 - 1
```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"
```