Navigation auf uzh.ch

Suche

Department of Informatics Database Technology

Database Lab/Datenbankpraktikum - Exercises

Exercises

  1. conceptual design (18.9.2024)
  2. logical design (25.9.2024)
  3. Consistency constraints (2.10.2024)
  4. Queries
    No lab on October 16 and 23 - use time for self-studies!
    1. Exercises (9./30.10. and 6.11. 2024)
    2. Performance (13.11.2023)
  5. Transactions (20.11.2024)
  6. Views (27.11.2024)
  7. User-defined functions and stored procedures (04.12.2024)
  8. Trigger (11.12.2024)
  9. Security and closing(18.12.2024)

Conceptual Design

The first exercise is to develop a conceptual model representing the entities of a carsharing organization. A German description of the system is here and an English translation here.

The reference solution for the conceptual design is here.

Logical Design

In the second lesson, we map the conceptual design onto a logical design. In addition to mapping entity types and relationships, please pay particular attention to the following cases:

  • how to implement specialization hierarchies;
  • how to deal with attributes whose type is again structured (such as addresses);
  • how to implement static attributes;
  • how to handle domains (and whether to use them at all);
  • how to handle collection-valued types (such as extras in Vehicle).

The Postgres manual about DDL can be found here (sections 5.1 and 5.10). In particular, read the section on inheritance. For the syntax definition how to create types and tables, see here and here.

The slides shown in the lab are here.
The solutions for the logical design in the form of PostgreSQL-DDL are here (types) and here (tables). A diagram reverse-engineered from the actual schema is here

Constraints

Define primary key, foreign key, uniqueness, not null, and semantic(check) constraints for the logical schema (see previous topic). See here for the relevant parts in the manual.
The slides shown in the lab are here.

Queries Preparation

In order to prepare the queries exercise, perform the following tasks:
  • Install Postgres if not done already
  • import the dump once it is available
  • make yourself familiar with the logical schema and database.
  • Write down 10 questions you would like to get answered from the Cash database (e.g., what is the most prevalent vehicle model?)

Queries

Documentation

Sample Data

Database Load via Restore

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:

  • create a database user cashu (if it does not yet exist)
  • create a database cashdb (if it does not yet exist) owned by user cashu
  • Rename the file from "cashdb.tar.txt" to "cashdb.tar".
  • Restore the database cashdb in pgadmin4 (In the object browser, navigate to "Databases", then right-click "cashdb" and select "restore"). Choose Format "Custom or tar".
  • .
  • Alternatively, execute the following command in a shell or command window:
    pg_restore -O -v  -d cashdb -U cashu -v cashdb.tar
The dump has been updated on October 9 after the lab and should work for version 16 now.

Database Load via Script

Alternatively, download this dump. Create a user and database a shown above. Then open the file in PGAdmin in the SQL tool or DBeaver and run it. You can also execute the file as shown in the lab with the following command:
psql -d cashdb -U cashu -f < path to downloaded file >

Exercises

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.

Bereichs-Navigation

Unterseiten von Übungen / Exercises