You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.5 KiB

\documentclass[a4paper,11pt]{article}
\usepackage{amsmath}
\usepackage{color}
\usepackage{colortbl}
\usepackage{anysize}
\usepackage{enumerate}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{listings}
\pagestyle{empty}
\setlength{\parindent}{0mm}
\begin{document}
%\def\loesung{}
\textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
{\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
Dipl.-Inf. Christian Pape}\\
%------------------------------------------------------------------------------
\textbf{Task 1 (SQL statements):}\\
%------------------------------------------------------------------------------
Write down the results of the following SQL statements on table T.
\begin{quote}
\begin{tabular}[t]{l|l|l|l}
T & A & B & C \\
\hline
& 1 & blue & 10 \\
& 2 & blue & 40 \\
& 3 & pink & 30 \\
& 4 & orange & 10 \\
& 5 & orange & 20 \\
& 6 & orange & 50 \\
& 7 & orange & 50 \\
& 8 & black & 50 \\
& 9 & black & 40 \\
& 10 & violet & 10 \\
& 11 & violet & 20 \\
& 12 & violet & 10 \\
\end{tabular}
\end{quote}
\begin{description}
\item[a.)] {\tt SELECT B, COUNT(*) FROM T GROUP BY B HAVING SUM(C)<=40}
\begin{quote}
\begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
\hline
B & COUNT(*) \\
\hline
\hline
\ifdefined\loesung
\textcolor{red}{pink} & \textcolor{red}{1} \\[0.3cm]
\hline
\textcolor{red}{violet} & \textcolor{red}{3} \\[0.3cm]
\hline
\textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
\hline
\textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
\else
& \\[0.3cm]
\hline
& \\[0.3cm]
\hline
& \\[0.3cm]
\hline
& \\[0.3cm]
\fi
\hline
\end{tabular}
\end{quote}
\item[b.)] {\tt SELECT B, COUNT(*) FROM T WHERE C>35 \\GROUP BY B HAVING COUNT(*)>=2}
\begin{quote}
\begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
\hline
B & COUNT(*) \\
\hline
\hline
\ifdefined\loesung
\textcolor{red}{orange} & \textcolor{red}{2} \\[0.3cm]
\hline
\textcolor{red}{black} & \textcolor{red}{2} \\[0.3cm]
\hline
\textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
\hline
\textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
\else
& \\[0.3cm]
\hline
& \\[0.3cm]
\hline
& \\[0.3cm]
\hline
& \\[0.3cm]
\fi
\hline
\end{tabular}
\end{quote}
\end{description}
\pagebreak
\textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
{\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
Dipl.-Inf. Christian Pape}\\
%------------------------------------------------------------------------------
\textbf{Task 2 (constraints \& integrity):}\\
%------------------------------------------------------------------------------
The following table definition with integrity constraints are given.
\begin{quote}
{\tt
\begin{tabbing}
CREATE TABLE T1 (\=A INT, B INT, C INT,\\
\>CONSTRAINT T1\_PS PRIMARY KEY (A,B),\\
\>CONSTRAINT T1\_SK UNIQUE (C));\\
\\
CREATE TABLE T2 (A INT, B INT, C INT, D INT, E INT,\\
\>CONSTRAINT T2\_PS PRIMARY KEY (A),\\
\>CONSTRAINT T2\_FS1 FOREIGN KEY (B,C) REFERENCES T1(A,B),\\
\>CONSTRAINT T2\_FS2 FOREIGN KEY (D) REFERENCES T1(C),\\
\>CONSTRAINT T2\_E\_NN CHECK (E IS NOT NULL),\\
\>CONSTRAINT T2\_E\_13 CHECK (E BETWEEN 1 AND 3)); \\
\end{tabbing}}
\end{quote}
The table T1 and T2 contain the following tuples. NULL values are indicated by a hyphen (-).
\begin{quote}
\begin{tabular}[t]{l|l|l|l}
T1 & A & B & C \\
\hline
& 1 & 1 & 5 \\
& 2 & 2 & 10 \\
& 3 & 3 & 15 \\
& 4 & 4 & 20 \\
& 5 & 5 & 25 \\
\end{tabular}
\hspace{2cm}
\begin{tabular}[t]{l|l|l|l|l|l}
T2 & A & B & C & D & E\\
\hline
& 100 & - & - & 15 & 1 \\
& 101 & 2 & 2 & 25 & 2 \\
& 102 & 2 & 2 & - & 3 \\
& 103 & 3 & 3 & 10 & 3 \\
& 104 & 3 & 3 & 10 & 3 \\
\end{tabular}
\end{quote}
Which of the following INSERT-statements are violating/not violating the defined integrity constraints? Only one integrity constraint will be violated for each statement. Enter the name of the violated integrity constraint or ''none'' if all conditions are met.
\begin{tabular}[t]{|l|l|l|}
\hline
Nr. & INSERT-statement & Violated constraint \\[0.3cm]
\hline
1 & {\tt INSERT INTO T1 VALUES (1, 2, 5)} & \ifdefined\loesung \textcolor{red}{T1\_SK} \fi \\[0.3cm]
\hline
2 & {\tt INSERT INTO T1 VALUES (1, 2, 30)} & \ifdefined\loesung \textcolor{red}{none} \fi \\[0.3cm]
\hline
3 & {\tt INSERT INTO T1 VALUES (1, 1, 50)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
\hline
4 & {\tt INSERT INTO T1 VALUES (1, NULL, NULL)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
\hline
5 & {\tt INSERT INTO T2 VALUES (117, 2, 2, 5, 5)} & \ifdefined\loesung \textcolor{red}{T2\_E\_13} \fi \\[0.3cm]
\hline
6 & {\tt INSERT INTO T2 VALUES (109, 3, 1, 10, 3)} & \ifdefined\loesung \textcolor{red}{T2\_FS1} \fi \\[0.3cm]
\hline
7 & {\tt INSERT INTO T2 VALUES (103, 1, 1, 20, 2)} & \ifdefined\loesung \textcolor{red}{T2\_PS} \fi \\[0.3cm]
\hline
8 & {\tt INSERT INTO T2 VALUES (110, 4, 4, 35, 1)} & \ifdefined\loesung \textcolor{red}{T2\_FS2} \fi \\[0.3cm]
\hline
\end{tabular}
\pagebreak
\textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
{\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
Dipl.-Inf. Christian Pape}\\
%------------------------------------------------------------------------------
\textbf{Task 3 (relations \& DDL-statements):}\\
%------------------------------------------------------------------------------
The following tables and DDL-statements are given. Please note: an exam with a grade other than 5.0 is passed.
\begin{figure}[htb]
\begin{minipage}{0.30\linewidth}
\includegraphics[width=38mm]{images/task3-chen.pdf}
\end{minipage}
%\hfill
\begin{minipage}{0.55\linewidth}
\scriptsize\lstinputlisting[numbers=none]{queries/task3-ddl.sql}
\end{minipage}
\end{figure}
\begin{description}
\item[a.)] What is defined in the table {\tt STUDENT}?
\ifdefined\loesung \textcolor{red}{
\begin{itemize}
\item the student's Id is the primary key
\item a student's Id have to be between 100000 and 999999
\item the GENDER column is restricted to 'm' for male and 'f' for female
\end{itemize}}\else \vfill \fi
\item[b.)] What is defined in the table {\tt EXAM}?
\ifdefined\loesung \textcolor{red}{
\begin{itemize}
\item the primary key is composed of the student's Id, the attempt and the course name
\item an exam can be taken three times
\item the possible grades for an exam are 1.0, 1.3, 1.7, 2.0, 2.3, 2.7, 3.0, 3.3, 3.7, 4.0, 5.0
\item the referenced student Id must exist in the {\tt STUDENT} table ({\tt FOREIGN KEY})
\item the deletion of a student will also delete all associated exams ({\tt ON DELETE CASCADE})
\end{itemize}}\else \vfill \fi
\item[c.)] Define a SQL query to find students (student's Id, firstname, lastname and course) who failed in the third attempt?
\begin{quote}
\ifdefined\loesung \textcolor{red}{\tt SELECT S.STUDENT\_ID, S.LASTNAME, E.COURSE FROM STUDENT S, EXAM E \\ WHERE S.STUDENT\_ID=E.STUDENT\_ID AND ATTEMPT=3 AND GRADE=5}\else \vfill \fi
\end{quote}
\item[d.)] Define a SQL query to report the average attempts for male and female students?
\begin{quote}
\ifdefined\loesung \textcolor{red}{\tt SELECT S.GENDER, AVG(ATTEMPT) FROM STUDENT S, EXAM E \\ WHERE S.STUDENT\_ID=E.STUDENT\_ID AND NOT GRADE=5 GROUP BY S.GENDER}\else \vfill \fi
\end{quote}
\end{description}
%------------------------------------------------------------------------------
\end{document}
%------------------------------------------------------------------------------