[DMDB] query language intro

This commit is contained in:
2026-06-22 17:47:35 +02:00
parent 2b066eab3c
commit 4488ccce81
3 changed files with 25 additions and 1 deletions
Binary file not shown.
@@ -0,0 +1,22 @@
\subsection{Query Language}
The basic structure of a \sql\ statement is \texttt{SELECT I FROM T WHERE C},
which corresponds to $\Pi_{\texttt{I}}(\sigma_{\texttt{C}} \texttt{T})$.
We can set \texttt{I = *} if we want to return all columns for a table.
To rename, we can set \texttt{I = Column as Name, Column2 as Name2}, etc
% TODO: Make RA an acronym, too
\inlinetheorem Every SPJR RA expression can be written in \texttt{SELECT ... FROM ... WHERE ...} form:
\begin{tables}{lll}{Operation & Notation & SQL}
Selection & $\sigma_c(R)$ & \texttt{SELECT * FROM R WHERE c;} \\
Projection & $\Pi_{A_1, \ldots, A_n} R$ & \texttt{SELECT A1, \ldots, An FROM R;} \\
Cartesian Product & $R_1 \times R_2$ & \texttt{SELECT * FROM (R1, R2);} \\
Rename & $\rho_{a, b, c} R$ & \texttt{SELECT A as a, \ldots, B as c FROM R;} \\
Union & $R_1 \cup R_2$ & \texttt{R1 UNION R2;} \\
Difference & $R_1 - R_2$ & \texttt{R1 EXCEPT R2;} \\
Intersection & $R_1 - R_2$ & \texttt{R1 INTERSECT R2;} \\
\end{tables}
Since \sql\ implements bag and not set semantics, there is a \texttt{DISTINCT} keyword, which is used to remove duplicates.
For the last three operations, \texttt{R1} and \texttt{R2} typically are other \sql\ statements:
\mint{sql}|(SELECT name FROM FirstTable) UNION (SELECT name FROM SecondTable)|
+3 -1
View File
@@ -3,5 +3,7 @@
\input{parts/01_sql/00_intro.tex}
\input{parts/01_sql/01_ddl.tex}
\input{parts/01_sql/02_dml.tex}
\input{parts/01_sql/03_query-language/00_intro.tex}
\input{parts/01_sql/01_operations.tex}
% \input{parts/00_sql/}
% \input{parts/01_sql/}