HUMBOLDT UNIVERSITÄT ZU BERLIN Wirtschaftswissenschaftliche Fakultät Telefon: (030) 2093-5742 Institut für Wirtschaftsinformatik Telefax: (030) 2093-5741 Spandauer Str. 1 10178 Berlin E-mail: iwi@wiwi.hu-berlin.de Diplomprüfung Database Management Prof. Dr. Oliver Günther und Steffan Baron Sommersemester 2002 (I) Sie können in dieser Klausur bzw. Teilklausur maximal 30 Punkte erzielen. Wenn Sie mehrere Teilklausuren schreiben, beginnen Sie bitte die Beantwortung jeder Teilklausur auf einem separaten Bogen Papier. Vergessen Sie nicht, jeden eingereichten Bogen Papier mit Ihrem Namen zu versehen. Es sind keine Hilfsmittel zugelassen. Die Aufgaben kommen in deutscher und in englischer Fassung. Die zwei Fassungen sind identisch, bis auf die Namen von Tabellen und Spalten. Daher dürfen Sie nur eine Fassung nutzen. Sie können auf Deutsch oder auf Englisch antworten. In this exam (Klausur) or partial exam (Teilklausur), you can obtain at most 30 credits. If you write more than one partial exam, please write the solutions to each partial exam on a separate sheet of paper. Do not forget to write your name on each sheet of paper. You are not allowed to use any books, personal notes, or other auxiliary material. There is a German and an English version of the exercises. Both versions are identical, except of the names of tables and columns. Therefore, you must use only one version. You can write the answers on German or English. Aufgabe Max. Punkte Erworbene Punkte Exercise Max. Points Points obtained 1 (a) 5 Teilsumme 1 2 (a) 3 (b) 3 (c) 3 (d) 3 (e) 3 Teilsumme 2 3 (a) 2 (b) 2 (c) 4 (d) 2 Teilsumme 3 SUMME
ENGLISH VERSION ENGLISCHE FASSUNG Description of the application for exercises 1 and 2. The following relational schema is used to store information about orders from an online shop. The primary key of each relation is underlined. transactions (transid, orderdate) For each transaction, an identifier (transid, data type integer) along with the respective order date (orderdate, data type date) is stored. orders (transid, product) In this table, for each ordered product the product name (product, data type varchar2(9)) and the identifier of the transaction in which the product was ordered is saved. 1. ER-Modeling (a) (5 points) Draw an Entity-Relationship diagram for this application. You may use either the classical ER notation (with rectangles, diamonds, etc.) or the Oracle Designer notation. Clearly mark the type of all relationships. 2. SQL (a) (3 points) Create a query to display the number of transactions in each month. Hint: You may use the function to_char(attribute, format) which converts attribute into a string according to the given format statement. For example, if order date is January 19, 2002, to_char(orderdate, DD:MON:YYYY ) returns the string 19:JAN:2002. (b) (3 points) Create the view JUNE_TRANSACT which contains the transaction identifier, the order date and the productname for all transactions of June. (c) (3 points) Determine the number of transactions in June that contain both Butter and Milk. (d) (3 points) Write a query to display all transactions in June with more than 5 items. (e) (3 points) Determine the maximum number of items in a single transaction in June. 3. Consider the following database schema, HTML/PHP form definition and code fragment. Database Schema: Customers (LoginName, Password, RealName, Address, Balance) Orders (OrderNo, Date, Customer) Contains (OrderNo, Product, Amount) HTML/PHP Form Definition: <form action="action.php" method="post"> Login name: <input type="text" name="login_name"> Password: <input type="text" name="password"> <input type="submit"> </form>
action.php: <?php $conn = mysql_connect("localhost", "guenther", ""); $res = mysql_query( "SELECT Product FROM Customers, Orders, Contains WHERE Customer = $login_name AND Customer = LoginName AND Password = $password ", $conn); print "<TABLE>\n"; do { $data = mysql_fetch_array($res); if (!is_array($data)) { break; } print " <TR>\n"; print " <TD>"; print implode("</td>\n <TD>", $data); print" </TR>\n"; } while ($data); print "</TABLE>\n";?> (a) (2 points) What does this code do? (b) (2 points) What does the program do if somebody uses a wrong login name or a wrong password? (c) (4 points) Modify the code such that customers see their account balance immediately after logging in. (d) (2 points) Where in the architecture of a web-based information system does this code run (on which servers or clients)?
GERMAN VERSION DEUTSCHE FASSUNG Anwendungsbeschreibung für die Aufgaben 1 und 2. Das folgende Relationenschema wird zur Speicherung der Bestelldaten eines Online-Shops verwendet. Die Attribute, die zum Primärschlüssel gehören, sind unterstrichen. transaktionen (transid, bestelldatum) Für jede Transaktion wird eine Kennung (transid, Datentyp integer) und das jeweilige Bestelldatum (bestelldatum, Datentyp date) gespeichert. bestellungen (transid, produkt) In dieser Tabelle wird für jedes bestellte Produkt der Produktname (produkt, Datentyp varchar2(9)) und die Kennung der Transaktion, in der das Produkt bestellt wurde, gespeichert. 1. ER-Modellierung (a) (5 Punkte) Zeichnen Sie das Entity-Relationship-Modell für diese Anwendung. Sie können die klassische ER-Notation (mit Rechtecken, Rauten usw.) oder die Notation des Oracle Designer verwenden. Kennzeichnen Sie dabei eindeutig den Beziehungstyp für alle Beziehungen. 2. SQL (a) (3 Punkte) Schreiben Sie eine Anfrage, die die Anzahl der Transaktionen in jedem Monat ausgibt. Hinweis: Sie können die Funktion to_char(attribut, format) verwenden, die das Attribut attribut gemäß der Formatangabe format in eine Zeichenkette umwandelt. Lautet das Bestelldatum bspw. 19. Januar 2002, gibt to_char(orderdate, DD:MON:YYYY ) die Zeichenkette 19:JAN:2002 zurück. (b) (3 Punkte) Legen Sie die Sicht JUNI_TRANSAKT an, die für alle Transaktionen im Monat Juni die Transaktionskennung, das Bestelldatum und den Produktnamen enthält. (c) (3 Punkte) Bestimmen Sie die Anzahl der Transaktionen im Juni, die Butter und Milch enthalten. (d) (3 Punkte) Geben Sie eine Anfrage an, die alle Transaktionen im Monat Juni ausgibt, die mehr als 5 Produkte enthalten. (e) (3 Punkte) Bestimmen Sie die maximale Anzahl von Produkten, die in einer einzelnen Transaktion im Juni bestellt wurden. 3. Betrachten Sie das folgende Relationenschema, die HTML/PHP-Formular-Definition und den angegebenen Quelltext-Ausschnitt. Relationenschema: Kunden (Nutzername, Passwort, Klarname, Adresse, Kontostand) Bestellungen (BestellNr, Datum, Kunde) Enthaelt (BestellNr, Produkt, Betrag)
HTML/PHP-Formular-Definition: <form action="action.php" method="post"> Nutzername: <input type="text" name="login_name"> Passwort: <input type="text" name="password"> <input type="submit"> </form> action.php: <?php $conn = mysql_connect("localhost", "guenther", ""); $res = mysql_query( "SELECT Produkt FROM Kunden, Bestellungen, Enthaelt WHERE Kunde = $login_name AND Kunde = Nutzername AND Passwort = $password ", $conn); print "<TABLE>\n"; do { $data = mysql_fetch_array($res); if (!is_array($data)) { break; } print " <TR>\n"; print " <TD>"; print implode("</td>\n <TD>", $data); print" </TR>\n"; } while ($data); print "</TABLE>\n";?> (a) (2 Punkte) Was macht dieses Programm? (b) (2 Punkte) Was macht das Programm, wenn jemand einen falschen Nutzernamen oder ein falsches Paßwort benutzt? (c) (4 Punkte) Ändern Sie den Quelltext derart, daß den Kunden unmittelbar nach der Anmeldung ihr Kontostand angezeigt wird. (d) (2 Punkte) Wo in einem WWW-basierten Informationssystem wird dieses Programm ausgeführt, auf dem Server oder auf dem Client?