aboutsummaryrefslogtreecommitdiff
path: root/blog/content/notes/tech/about-relational-databases.gmi
blob: 1760f0b357cc5ad045bbfec8b4b772661cf5b45e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# About relational databases

## What is a relation?

A common misconception is that the "relations" in a relational database are about relations between database tables.

Actually, the relations in a relational database are the tables.

A relation "relates" a set of values with another set of values.

For example, a relation can relate the name of a person with their birth date and birth place. For example:

(person name) => (birth date, birth place)
(Alice) => (1979-12-03, Barcelona)
(Bob) => (1995-03-04, Paris)
...

Many computer languages have similar concepts:

* Python mapping types such as dict
* C++ std::map
* Java java.util.Map
* C# System.Collections.Generic.Dictionary
* JavaScript Object
* PHP arrays

Relations are a natural concept, so although non-relational data systems exist, most data can be stored as relations.

## Random notes

### About schema design

* Only denormalize when provably forced to.
* If implementing business logic requires complex queries, then the schema might not be optimal.
* Normalization is not always obvious. It might look redundant to include the product unit price in the line item of an order, because the database already stores the product price, but you need to record the price at the time of the order, which might not be permanent.

### Others

=> real-time-relations Real-time relations describes a simpler relational database for real-time software.