• Keine Ergebnisse gefunden

Relational Databases I Exercise Sheet 08: SQL 1 (36 points)

N/A
N/A
Protected

Academic year: 2021

Aktie "Relational Databases I Exercise Sheet 08: SQL 1 (36 points)"

Copied!
3
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Relational Databases I

Exercise Sheet 08: SQL 1 (36 points)

(due by Thursday, December 12, 2013)

Please note: You need 50% of all exercise points to receive the Studienleistung. Solutions have to be turned in on paper until Thursday before the lecture either in the lecture hall or into our mailbox (Informatikzentrum 2nd floor). Please write your matriculation numbers and your tutorial group number on your solutions! You may answer in German or English. You need to pass both the exercises and the exam for the RDB 1 module! Unless otherwise specified: Always use your own words!

Exercise 0 – Database Schema (0 points)

The exercises 0 to 3 are based on the following database schema (the dom function is not given):

Comic(no NOT NULL, title, pages, publisher) SuperPower(name NOT NULL, effect)

PoweredPerson(alias NOT NULL, firstname NOT NULL, lastname, evilness_level) SuperHero(alias → PoweredPerson NOT NULL, cape)

SuperVillain(alias → PoweredPerson NOT NULL)

Archnemesis(hero → SuperHero NOT NULL, villain → SuperVillain NOT NULL) FightIn(comic → Comic NOT NULL, hero → SuperHero NOT NULL,

villain → SuperVillain NOT NULL)

HasPowerSince(comic → Comic NOT NULL, alias → PoweredPerson NOT NULL, power → SuperPower NOT NULL)

All exercises worth 0 points are optional. However, they recapitulate lecture contents and may be a good exercise.

a) Translate the database schema into a corresponding (E)ER diagram. (0 points)

b) After modeling the (E)ER diagram in exercise a) have a look at the ER relationship type for HasPowerSince. Find the most reasonable cardinalities for the three participating entity types by drawing a set diagram like in lecture 2 slide 47. (0 points)

c) Provide the missing dom functions for the database schema. (0 points)

d) Translate the database schema into a corresponding UML diagram using the dom functions from exercise c). (0 points)

Exercise 1 – Understanding SQL (12 points)

a) Why does SQL need three valued logic? (1 points)

b) Why does SQL not implement a mandatory unique tuple constraint like used in relational algebra? (1 points)

c) Briefly explain the differences between the HAVING and the WHERE clause. (2 point)

d) Does the expressiveness of SQL change if you remove the HAVING clause? Explain your answer!

(2 points)

e) What is the difference between a correlated and an uncorrelated subquery? Why are uncorrelated subqueries generally preferred over correlated subqueries? (2 points)

(2)

Relational Databases I

f) What is the difference between a set and a bag? How can you enforce the DBMS to return a set instead of a bag? (2 points)

g) Given the two statements below:

(1) SELECT COUNT(no) FROM comic;

(2) SELECT COUNT(title) FROM comic;

Explain the difference between the two statements. Which statement would you use when, and why? (2 points)

Exercise 2 – SQL Queries on a Database Schema (12 points)

Given the relational database schema in Exercise 0 and based on the SQL syntax from the lecture, provide an SQL query for each of the following tasks:

a) A query for all comics having more than 50 pages. (1 point)

b) A query for the first name of all powered persons with a last name that starts with an A and is at least 3 characters long. (2 points)

c) A query that returns the number of super powers for each different effect. Skip those effects that have less than 4 super powers. (2 points)

d) A query for the first names of those villain(s) having the least number of archnemesis’ (but at least one). (3 points)

e) A query for the first and last names of those powered person(s) that fought the most enemies in just one comic. (4 points)

Exercise 3 – SQL Queries on a Database Instance (12 points)

Given the following database instance fragment as well as the corresponding database schema from Exercise 0:

Based on the SQL syntax from the lecture, provide an SQL query for each of the following tasks:

a) The super villain table is an excerpt of the powered person table. Provide a query on the powered person table that reproduces the super villain table. (1 point)

(3)

Relational Databases I

b) A query for all super heroes having no cape. (1 point)

c) A query for the names of all powers of Young Nastyman and the no of the comic they first appeared in, ordered by their appearance (newest first). If two powers appeared at the same time, sort them alphabetically by their name. (2 points)

d) A query for the number of pages I would have to read if I wanted to read all Marvel comics in the database. (2 points)

e) A query that states if the average powered person is evil (evilness > 0) or good (evilness ≤ 0), depending on all powered persons’ evilness levels. (2 points)

f) A query for the aliases of all super heroes that fought super villains in a comic with an id from 10 to 20, the comic’s title, and the number of powers the respective hero already possessed in that comic. (4 points)

Referenzen

ÄHNLICHE DOKUMENTE

If you forget to write your Matrike- lnummer and/or your tutorial group number, you get automatically 0 points.. Your solutions may be in German

What are the main steps that need to be processed in order to answer a user’s query.. What needs to be optimized in

Exercises will be discussed on Friday on week after the respective lecture was given. The handouts are optional and do not have to be handed in. They only serve as optional

Solutions have to be turned in on paper until Thursday before the lecture either in the lecture hall or into our mailbox (Informatikzentrum 2nd floor)!. Please write

c) Give an extensional or an intensional set specifications of the following tasks: (3 points) i. All integers between -5 and 5. The aliases of the Fantastic Four. All natural

e) For each power type of powers with greater reach than 5, return the number of heroes that possess it.

e) A list of last names of all those students that took at least all exams in all courses with a course number between 110 and

Given a database schema based on the CREATE TABLE statements from Exercise 0 and using the SQL syntax introduced in the lecture, provide INSERT, UPDATE, and DELETE statements for the