Datenbankpraktikum - Exercises
Übungen
- conceptual design (15.9.2015)
- logical design (29.9.2015)
- Consistency Constraints (6.10.2015)
- Updates (06.10.2015)
- Queries (13.10/20.10.)
note that there is no lab on October 27 and November 3! As discussed in the last session, please finish the query part at home. Remember to store your solutions. - Transactions (10.11.2015)
- Views (17.11.2015)
- User-defined functions and stored procedures (24.11. 2015)
- Trigger (1.12.2015)
- JDBC (8.12./15.12.2015)
Logical Design
In the second lesson, we map the conceptual design onto a logical design.
See here for logical schema design (table definition) in PostgreSQL:
(
PostgreSQL DDL, 5.1, 5.8, 5.11).
The solutions for the logical design in the form of PostgreSQL-DDL are
here
(types) and
here (tables).
Queries
A page with the SQL exercises can be found
here.
You can also download the SQL exercises
here.
Please record your own solutions in a file so that they can be compared to the reference
solution later.
Preparation:
- Queries are described in the Postgres-Manual: here and here.
- In order to have sufficient data to test, please load a database dump containing the
table definitions and data. The dump file is
here. Restore the dump as follows:
- Rename the file from "cashdb-plain.txt" to "cashdb-plain.tar".
- Create the database cashdb and restore it in pgadmin3
(In the object browser, navigate to "Databases", then right-click "cashdb"
and select "restore")
. Alternatively, execute the following command in a shell or command window:pg_restore -c -C -d cashdb -U cashu -i -v cashdb-plain.tar
In case pg_restore cannot be found (may happen on Windows), execute the script pg_env.bat first. This script is usually in the installation directory of PostgreSQL.
- Slides with examples for temporary views and recursive queries are here
- Sample code for recursive queries is here
- Sample code for analytic queries is here
- Die Musterlösungen sind hier.
Views
Preparation: Views are documented
here.
In the exercises on views we will also cover other approaches how to implement specialization
hierarchies. The script containing the table definitions for the two hierarchies
(Member and Vehicle) without table inheritance are
here. A script for filling the tables is
here.
Exercises are
here.
Die Musterlösungen für die Übungen zu Sichten sind
hier.
User-defined Funktiones and Stored Procedures
Preparation: Chapter 35, 38, 39
in the manual. We wil lonly use SQL and PL/pgSQL as
implementation languages. You thus do not need to read the sections on PL/TCL,
PL/Perl and PL/Python.
Here are exercises for
functions and procedures.
Here are solutions for
functions,
procedures, and
table functions.
Trigger
Preparation: Chapter 36 and 37
in the manual.
Here are the exercises for
Triggers.
Solutions are
here
and
here.
JDBC
A short introduction into JDBC is
here.
An introduction into JDBC on an old Postgres-page (Postgres 7.4, but the JDBC part is
still accurate):
link.
Until December 8 you should have a Java development environment installed and should be familiar
with it. Possible IDEs are
(NetBeans,
Eclipse, JDeveloper, ...). In the lab, weĺl show first steps with NetBeans.
Please also download a JDBC-driver for Postgres (e.g. the Type-4-driver
here).
The goal of the JDBC-exercise is to complete several
Java
programs with the appropriate JDBC-calls.
Complete the programs in the following sequence:
- ListPersMembers.java
- GetMembers.java
- OpenReservations.java
- CancelReservations.java
- CreateInvoices.java