mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-07-27 21:29:09 +02:00
[DMDB] relational model, relational algebra, SQL very basics
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
In the relational model, relations are sets of tuples (similar to \glspl{record}). They are denoted $R(f_1: D_1, \ldots, f_n: D_n)$,
|
||||
or sometimes simply $R(D_1, \ldots, D_n)$.
|
||||
An \bi{instance} is a \bi{set} of tuples $I_R \subseteq D_1 \times \ldots \times D_n$.
|
||||
|
||||
\inlineintuition You can think of the instance to be the rows in the table.
|
||||
|
||||
\shade{orange}{Important} We define relations as \bi{mathematical sets}. This means that they cannot contain duplicates and the order does not matter.
|
||||
Database engines may elect to do this differently, but this course assumes set semantics for the relational model.
|
||||
@@ -0,0 +1,11 @@
|
||||
\subsubsection{Keys}
|
||||
\inlinedefinition[Candidate Key] The minimal set of fields that identify each tuple uniquely
|
||||
|
||||
\inlinedefinition[Primary Key] A single candidate key, i.e. just a single field.
|
||||
We mark the primary key using \underline{underlining} in visual \glspl{schema}.
|
||||
Formally, we write $R(\underline{k : D_k}, a:D_a, b:D_b)$ for a given relation, with all valid instances fulfilling
|
||||
\[
|
||||
I \subseteq D_k \times D_a \times D_b \land \forall (k, a, b), (k', a', b') \in I : k = k' \rightarrow (a, b) = (a', b')
|
||||
\]
|
||||
i.e. if the key is equal, so is the rest of the tuple (thus they are one and the same\footnote{\hlhref{https://www.youtube.com/watch?v=tGeSEbYzhBU}{Heidrun is her name}}).
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
\subsubsection{Queries}
|
||||
We write queries in a relational model using the following set notation (using \acrshort{sql} for an actual DB):
|
||||
\[
|
||||
\{ (r, p) \divider r \in \texttt{Supplies} \land p \in \texttt{Parts} \land \texttt{r.pid = p.pid} \land \texttt{p.name = "A"} \}
|
||||
\]
|
||||
The query language thus processes an entire set at a time and applies set operations over the relations.
|
||||
Reference in New Issue
Block a user