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

6 years ago
  1. \documentclass[a4paper,11pt]{article}
  2. \usepackage{amsmath}
  3. \usepackage{color}
  4. \usepackage{colortbl}
  5. \usepackage{anysize}
  6. \usepackage{enumerate}
  7. \usepackage[utf8]{inputenc}
  8. \usepackage{amssymb}
  9. \usepackage{amsmath}
  10. \usepackage{tikz}
  11. \usepackage{listings}
  12. \pagestyle{empty}
  13. \setlength{\parindent}{0mm}
  14. \begin{document}
  15. %\def\loesung{}
  16. \textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
  17. {\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
  18. Dipl.-Inf. Christian Pape}\\
  19. %------------------------------------------------------------------------------
  20. \textbf{Task 1 (SQL statements):}\\
  21. %------------------------------------------------------------------------------
  22. Write down the results of the following SQL statements on table T.
  23. \begin{quote}
  24. \begin{tabular}[t]{l|l|l|l}
  25. T & A & B & C \\
  26. \hline
  27. & 1 & blue & 10 \\
  28. & 2 & blue & 40 \\
  29. & 3 & pink & 30 \\
  30. & 4 & orange & 10 \\
  31. & 5 & orange & 20 \\
  32. & 6 & orange & 50 \\
  33. & 7 & orange & 50 \\
  34. & 8 & black & 50 \\
  35. & 9 & black & 40 \\
  36. & 10 & violet & 10 \\
  37. & 11 & violet & 20 \\
  38. & 12 & violet & 10 \\
  39. \end{tabular}
  40. \end{quote}
  41. \begin{description}
  42. \item[a.)] {\tt SELECT B, COUNT(*) FROM T GROUP BY B HAVING SUM(C)<=40}
  43. \begin{quote}
  44. \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
  45. \hline
  46. B & COUNT(*) \\
  47. \hline
  48. \hline
  49. \ifdefined\loesung
  50. \textcolor{red}{pink} & \textcolor{red}{1} \\[0.3cm]
  51. \hline
  52. \textcolor{red}{violet} & \textcolor{red}{3} \\[0.3cm]
  53. \hline
  54. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  55. \hline
  56. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  57. \else
  58. & \\[0.3cm]
  59. \hline
  60. & \\[0.3cm]
  61. \hline
  62. & \\[0.3cm]
  63. \hline
  64. & \\[0.3cm]
  65. \fi
  66. \hline
  67. \end{tabular}
  68. \end{quote}
  69. \item[b.)] {\tt SELECT B, COUNT(*) FROM T WHERE C>35 \\GROUP BY B HAVING COUNT(*)>=2}
  70. \begin{quote}
  71. \begin{tabular}[t]{|p{2.5cm}|p{2.5cm}|}
  72. \hline
  73. B & COUNT(*) \\
  74. \hline
  75. \hline
  76. \ifdefined\loesung
  77. \textcolor{red}{orange} & \textcolor{red}{2} \\[0.3cm]
  78. \hline
  79. \textcolor{red}{black} & \textcolor{red}{2} \\[0.3cm]
  80. \hline
  81. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  82. \hline
  83. \textcolor{red}{} & \textcolor{red}{} \\[0.3cm]
  84. \else
  85. & \\[0.3cm]
  86. \hline
  87. & \\[0.3cm]
  88. \hline
  89. & \\[0.3cm]
  90. \hline
  91. & \\[0.3cm]
  92. \fi
  93. \hline
  94. \end{tabular}
  95. \end{quote}
  96. \end{description}
  97. \pagebreak
  98. \textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
  99. {\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
  100. Dipl.-Inf. Christian Pape}\\
  101. %------------------------------------------------------------------------------
  102. \textbf{Task 2 (constraints \& integrity):}\\
  103. %------------------------------------------------------------------------------
  104. The following table definition with integrity constraints are given.
  105. \begin{quote}
  106. {\tt
  107. \begin{tabbing}
  108. CREATE TABLE T1 (\=A INT, B INT, C INT,\\
  109. \>CONSTRAINT T1\_PS PRIMARY KEY (A,B),\\
  110. \>CONSTRAINT T1\_SK UNIQUE (C));\\
  111. \\
  112. CREATE TABLE T2 (A INT, B INT, C INT, D INT, E INT,\\
  113. \>CONSTRAINT T2\_PS PRIMARY KEY (A),\\
  114. \>CONSTRAINT T2\_FS1 FOREIGN KEY (B,C) REFERENCES T1(A,B),\\
  115. \>CONSTRAINT T2\_FS2 FOREIGN KEY (D) REFERENCES T1(C),\\
  116. \>CONSTRAINT T2\_E\_NN CHECK (E IS NOT NULL),\\
  117. \>CONSTRAINT T2\_E\_13 CHECK (E BETWEEN 1 AND 3)); \\
  118. \end{tabbing}}
  119. \end{quote}
  120. The table T1 and T2 contain the following tuples. NULL values are indicated by a hyphen (-).
  121. \begin{quote}
  122. \begin{tabular}[t]{l|l|l|l}
  123. T1 & A & B & C \\
  124. \hline
  125. & 1 & 1 & 5 \\
  126. & 2 & 2 & 10 \\
  127. & 3 & 3 & 15 \\
  128. & 4 & 4 & 20 \\
  129. & 5 & 5 & 25 \\
  130. \end{tabular}
  131. \hspace{2cm}
  132. \begin{tabular}[t]{l|l|l|l|l|l}
  133. T2 & A & B & C & D & E\\
  134. \hline
  135. & 100 & - & - & 15 & 1 \\
  136. & 101 & 2 & 2 & 25 & 2 \\
  137. & 102 & 2 & 2 & - & 3 \\
  138. & 103 & 3 & 3 & 10 & 3 \\
  139. & 104 & 3 & 3 & 10 & 3 \\
  140. \end{tabular}
  141. \end{quote}
  142. 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.
  143. \begin{tabular}[t]{|l|l|l|}
  144. \hline
  145. Nr. & INSERT-statement & Violated constraint \\[0.3cm]
  146. \hline
  147. 1 & {\tt INSERT INTO T1 VALUES (1, 2, 5)} & \ifdefined\loesung \textcolor{red}{T1\_SK} \fi \\[0.3cm]
  148. \hline
  149. 2 & {\tt INSERT INTO T1 VALUES (1, 2, 30)} & \ifdefined\loesung \textcolor{red}{none} \fi \\[0.3cm]
  150. \hline
  151. 3 & {\tt INSERT INTO T1 VALUES (1, 1, 50)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
  152. \hline
  153. 4 & {\tt INSERT INTO T1 VALUES (1, NULL, NULL)} & \ifdefined\loesung \textcolor{red}{T1\_PS} \fi \\[0.3cm]
  154. \hline
  155. 5 & {\tt INSERT INTO T2 VALUES (117, 2, 2, 5, 5)} & \ifdefined\loesung \textcolor{red}{T2\_E\_13} \fi \\[0.3cm]
  156. \hline
  157. 6 & {\tt INSERT INTO T2 VALUES (109, 3, 1, 10, 3)} & \ifdefined\loesung \textcolor{red}{T2\_FS1} \fi \\[0.3cm]
  158. \hline
  159. 7 & {\tt INSERT INTO T2 VALUES (103, 1, 1, 20, 2)} & \ifdefined\loesung \textcolor{red}{T2\_PS} \fi \\[0.3cm]
  160. \hline
  161. 8 & {\tt INSERT INTO T2 VALUES (110, 4, 4, 35, 1)} & \ifdefined\loesung \textcolor{red}{T2\_FS2} \fi \\[0.3cm]
  162. \hline
  163. \end{tabular}
  164. \pagebreak
  165. \textsc{Hochschule Fulda}{\small\hfill GSD Database \& SQL questionnaire}\\
  166. {\small Fachbereich Angewandte Informatik{\small\hfill SS 18}\\
  167. Dipl.-Inf. Christian Pape}\\
  168. %------------------------------------------------------------------------------
  169. \textbf{Task 3 (relations \& DDL-statements):}\\
  170. %------------------------------------------------------------------------------
  171. The following tables and DDL-statements are given. Please note: an exam with a grade other than 5.0 is passed.
  172. \begin{figure}[htb]
  173. \begin{minipage}{0.30\linewidth}
  174. \includegraphics[width=38mm]{images/task3-chen.pdf}
  175. \end{minipage}
  176. %\hfill
  177. \begin{minipage}{0.55\linewidth}
  178. \scriptsize\lstinputlisting[numbers=none]{queries/task3-ddl.sql}
  179. \end{minipage}
  180. \end{figure}
  181. \begin{description}
  182. \item[a.)] What is defined in the table {\tt STUDENT}?
  183. \ifdefined\loesung \textcolor{red}{
  184. \begin{itemize}
  185. \item the student's Id is the primary key
  186. \item a student's Id have to be between 100000 and 999999
  187. \item the GENDER column is restricted to 'm' for male and 'f' for female
  188. \end{itemize}}\else \vfill \fi
  189. \item[b.)] What is defined in the table {\tt EXAM}?
  190. \ifdefined\loesung \textcolor{red}{
  191. \begin{itemize}
  192. \item the primary key is composed of the student's Id, the attempt and the course name
  193. \item an exam can be taken three times
  194. \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
  195. \item the referenced student Id must exist in the {\tt STUDENT} table ({\tt FOREIGN KEY})
  196. \item the deletion of a student will also delete all associated exams ({\tt ON DELETE CASCADE})
  197. \end{itemize}}\else \vfill \fi
  198. \item[c.)] Define a SQL query to find students (student's Id, firstname, lastname and course) who failed in the third attempt?
  199. \begin{quote}
  200. \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
  201. \end{quote}
  202. \item[d.)] Define a SQL query to report the average attempts for male and female students?
  203. \begin{quote}
  204. \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
  205. \end{quote}
  206. \end{description}
  207. %------------------------------------------------------------------------------
  208. \end{document}
  209. %------------------------------------------------------------------------------