Aufgabe: Relationale Datenbank Lorenz Mösenlechner, Thomas Rühr 15. November 2010 Begriffe I I Datenbank: Menge von Tabellen Tabelle: besteht aus I I Schema: Beschreibung des Tabellenaufbaus Extension: Menge von Tupeln, die die Daten beinhalten Beispiel I Supplier: I Product: I SP: S-SKey S1 S2 S3 S-SName Müller Meier Schmidt P-PKey P1 P2 SP-SKey S1 S2 S-City Ulm Stuttgart Ulm P-PName Nudeln Maultaschen SP-PKey P1 P1 SP-Qty 300 200 Darstellung der Datenbank I Assoziationsliste aus Tabellennamen und Tabellen: ((name1 . table1) (name2 . table2) ...) I get-db liefert die Datenbank zurück I reset-db setzt Datenbank in leeren Zustand zurück I get-table: Name → Table I add-table: Name × Table → DB I drop-table: Name → DB I replace-table: Name × Table → DB Darstellung von Tabellen I Liste aus Schema und Extension I I I Schema: Liste von Spaltennamen Extension: Liste von Tupeln, Tupel: Liste mit Einträgen für jede Spalte I make-table: schema × extension → table I get-schema: table → schema I get-extension: table → extension Benutzerkommandos I Datendefinition I I I db-create-table: name × schema → DB db-drop-table: name → DB Datenmanipulation I I I db-select: columns × tables × predicate → table db-delete: name × predicate → DB db-insert: name × tuple → DB Der Join I Kombination von zwei Tabellen: I I I Schema: Vereinigung Extension: Kreuzprodukt Beispiel: (join Supplier SP) S-SKey S1 S1 S2 S2 S3 S3 S-SName Müller Müller Meier Meier Schmidt Schmidt S-City Ulm Ulm Stuttgart Stuttgart Ulm Ulm SP-SKey S1 S2 S1 S2 S1 S2 SP-PKey P1 P1 P1 P1 P1 P1 SP-Qty 300 200 300 200 300 200 Selektion von Tupeln I filter-table: pred × table → table I Beispiel: (filter-table #’(lambda (tp) (eq (at ’scity tp) ’ulm)) (join ’supplier ’sp)) S-SKey S1 S1 S3 S3 S-Name Müller Müller Schmidt Schmidt S-City Ulm Ulm Ulm Ulm SP-SKey S1 S2 S1 S2 SP-PKey P1 P1 P1 P1 SP-Qty 300 200 300 200 Projektion I Heraussuchen einzelner Spalten I project: columns × table → table I Beispiel: (project ’(sname scity) supplier) S-Name Müller Meier Schmidt S-City Ulm Stuttgart Ulm Das db-select Kommando I Definition: (defun db-select (columns &key (from nil) (where #’(lambda (tp) T)))) I Vorgehen: 1. Bilde Joins aller Tabellen 2. Filtern der Tupel, die das where-Prädikat erfüllen 3. Projizieren der Spalten columns
© Copyright 2026 Paperzz