--- author: Florian Fischer theme: metropolis aspectratio: 169 header-includes: | \usepackage{adjustbox} \let\tightlist\relax --- ## Wiederholung - n:m Beziehungen ## Ein Versandhandel verwaltet Bestellungen in einer Tabelle mit folgendem Schema: ```{\small \texttt{BESTELLUNG[\underline{KdNr}; Name; Vorame; Adresse; Telefon; \underline{ArtNr}; Artikel; Preis; Anzahl; \underline{BDatum}]} }```{=latex} \adjustbox{width=\textwidth}{ \begin{tabularx}{1.1\textwidth}{|l X X p{1.7cm} X c l l c X|} \hline \rowcolor{blue!20!white}\underline{KdNr} & Name & Vorname & Adresse & Telefon & \underline{ArtNr} & Artikel & Preis & Anz. & \underline{BDatum} \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 3434 & Hemd & 22,90 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 2827 & Jeans & 69,95 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 6001 & Rasierer & 49,00 & 1 & 12.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 3434 & Hemd & 22,90 & 2 & 13.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 1007 & Bluse & 43,50 & 2 & 13.07.20 \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline \end{tabularx} } \pause ### \faIcon{desktop} Arbeitsauftrag - 3 min * Überlege Dir welche Informationen werden unnötig oft gespeichert? * Finde Probleme die durch das Tabellenschema entstehen wenn Datensätze geändert werden müssen. ## \faIcon{pencil-alt} \large Unter \beamerpgap{2}{\boldred{Redundanz}} versteht man die Mehrfachspeicherung von Daten. Beim Ändern, Löschen oder Einfügen von Datensätzen können dadurch Probleme entstehen, sogenannte \beamerpgap{3}{\boldred{Anomalien}}. ## \begin{tcolorbox}[colframe=orange, title=\faIcon{pencil-alt} UPDATE-Anomalie] Änderungen an Daten können zu Inkonsistenzen führen. \end{tcolorbox} \adjustbox{width=\textwidth}{ \begin{tabularx}{1.1\textwidth}{|l X X p{1.7cm} X c l l c X|} \hline \rowcolor{blue!20!white}\underline{KdNr} & Name & Vorname & Adresse & Telefon & \underline{ArtNr} & Artikel & Preis & Anz. & \underline{BDatum} \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline 123 & Mueller & Max & Postweg 8 & \textcolor{red}{555161} & 3434 & Hemd & 22,90 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & \textcolor{magenta}{555180} & 2827 & Jeans & 69,95 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & \textcolor{magenta}{555180} & 6001 & Rasierer & 49,00 & 1 & 12.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 3434 & Hemd & 22,90 & 2 & 13.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 1007 & Bluse & 43,50 & 2 & 13.07.20 \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline \end{tabularx} } ## \begin{tcolorbox}[colframe=orange, title=\faIcon{pencil-alt} DELETE-Anomalie] Beim Löschen können ungewollte andere Informationen verloren gehen. \end{tcolorbox} Welche Informationen gehen verloren wenn abgeschlossene Bestellungen gelöscht werden? ### Verlorene Information \pause * Kundendaten (Name, Vorname, Adresse, Telefon) * Produktinformationen (Artikel, Preis) ## \begin{tcolorbox}[colframe=orange, title=\faIcon{pencil-alt} INSERT-Anomalie] Neue Daten lassen sich nur einfügen, wenn \textbf{alle} Teile des Primärschlüssels bekannt sind. \end{tcolorbox} \adjustbox{width=\textwidth}{ \begin{tabularx}{1.1\textwidth}{|l X X p{1.7cm} X c l l c X|} \hline \rowcolor{blue!20!white}\underline{KdNr} & Name & Vorname & Adresse & Telefon & \underline{ArtNr} & Artikel & Preis & Anz. & \underline{BDatum} \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 3434 & Hemd & 22,90 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 2827 & Jeans & 69,95 & 1 & 12.07.20 \\ \hline 123 & Mueller & Max & Postweg 8 & 555180 & 6001 & Rasierer & 49,00 & 1 & 12.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 3434 & Hemd & 22,90 & 2 & 13.07.20 \\ \hline 224 & Nowak & Beate & Goldstr. 7 & 555788 & 1007 & Bluse & 43,50 & 2 & 13.07.20 \\ \hline \textcolor{red}{???} & \textcolor{red}{???} & \textcolor{red}{???} & \textcolor{red}{???} & \textcolor{red}{???} & \textcolor{red}{1974} & \textcolor{red}{Schuhe} & \textcolor{red}{99,95} & \textcolor{red}{???} & \textcolor{red}{???} \\ \hline \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots & \dots \\ \hline \end{tabularx} } \pause Ein neues Produkt kann erst aufgenommen werden, wenn es auch bereits bestellt wurde. ## \faIcon{pencil-alt} Arbeitsauftrag: Modellierung \hfill 7 min \large Erstelle ein Klassendiagramm das die Klassen der Bestelltabelle und ihre Beziehungen darstellt. Benenne die Beziehungen und gib ihre Kardinalitäten an. \textit{(Du musst keine Attributen der Klassen angeben.)} ## Lösung \centering \scalebox{1.3}{ \begin{tikzpicture} \node[draw] (k) {Kunde}; \node[draw,right=3cm of k] (b) {Bestellung}; \node[draw,right=3cm of b] (a) {Artikel}; \draw (k) -- (b) node[midway, above] {tätigt >}; \path (k) -- (b) node[very near start, above] {1}; \path (k) -- (b) node[very near end, above] {n}; \draw (b) -- (a) node[midway, above] {enthält >}; \path (b) -- (a) node[very near start, above] {m}; \path (b) -- (a) node[very near end, above] {n}; \end{tikzpicture} } ## \faIcon{pencil-alt} Arbeitsauftrag: Tabellenschema \hfill 7 min \large Erstelle ein Tabellenschema, das dein Klassendiagramm in eine Datenbank überträgt. Markiere Primär-/ und Fremschlüssels wie gewohnt. \textit{(Du musst keine Datentypen der Attribute angeben.)} ## Lösung \texttt{Kunde[\underline{KndNr}; Name; Vorname; Adresse; Telefon]} \texttt{Bestellung[\underline{BDatum; \dashuline{KndNr}}]} \texttt{Artikel[\underline{ArtNr}; Artikel; Preis]} \texttt{Enthaelt[\underline{\dashuline{BDatum; KndNr}; \dashuline{ArtNr}}; Anzahl]};