List of commits:
Subject Hash Author Date (UTC)
Added solution to second exam d8f62ded96991885a96d561db587988d453a28c8 aubert@math.cnrs.fr 2020-11-05 20:35:50
Quick fix on testing semicolons. 7f48d88d2ed69213d803a7736df3d50330cfecd1 aubert@math.cnrs.fr 2020-11-03 14:14:06
Added simple example to test if semicolon are important in SQL querries. 98097fb11558c08bad630fb3351f99ceb6777de7 aubert@math.cnrs.fr 2020-11-03 14:11:22
Updated spots to https. a8daf1768395aa296bf0dd05783dd53c757d5d19 aubert@math.cnrs.fr 2020-10-05 16:18:44
Adding quiz #2 98e0ae5b8ce766524f60c91adb1040235e1bbf31 aubert@math.cnrs.fr 2020-10-02 19:00:15
Added exam 1 e2f62ae4bf26fcc4b86e8665060ccf3918e7abeb aubert@math.cnrs.fr 2020-09-24 12:51:36
worked on solution to first exam. b13ad99dd895f124df1b642fd990071fc09db294 aubert@math.cnrs.fr 2020-09-23 17:44:01
Added solution to first problem. 0948cee47ed78dc115fd69c7bcf96a312dd3162f aubert@math.cnrs.fr 2020-09-18 21:43:00
Added solution to problem 2 of Exam #1. 7ad20b3c0025a4de3fa00729de570c6fe9176773 aubert@math.cnrs.fr 2020-09-18 21:34:19
Added solution to project 1. de427d78745593ab53dc70e7129b67fee1d4489c aubert@math.cnrs.fr 2020-09-10 19:04:45
Added example for MAX and NULL values. b82a496a5ffbcecaf2c5851f18d1b08ce8732623 aubert@math.cnrs.fr 2020-09-10 13:14:13
Changed SQL code formatting. 6c3cad5a2545f46ab113f7df7a83457857d82ed8 aubert@math.cnrs.fr 2020-09-09 17:04:55
Cleaned code. 5bdb4faed3a83b81257734f1e1aced2890783f04 aubert@math.cnrs.fr 2020-09-03 21:35:41
Added the first project. 564a02887933f2395bc40d7d8a10833f657659fd aubert@math.cnrs.fr 2020-08-28 22:34:08
Week 2 edits, added quiz #1, couple of fixes, replaced single quote with double quotes. 3c9942731678900122088356db3a2cbabd99b9be aubert@math.cnrs.fr 2020-08-27 19:00:13
Added ressource for makefile. 7696c44bca707646530a7dbb71bf2e05badaa306 aubert@math.cnrs.fr 2020-08-03 16:00:23
Crystal's final edits. 714e3030423a836c4ba07890f9aa5e45f58ad15a aubert@math.cnrs.fr 2020-05-21 17:43:26
Converted an image into a figure (Movie example). c55e61ed5d11631e908d99b14ef10a0a0247bda0 aubert@math.cnrs.fr 2020-05-20 20:58:41
Re-formatted SQL code. 915442a1ba4d8baa120343f98de5ee39d4ac45f6 aubert@math.cnrs.fr 2020-05-18 15:52:06
Fixed Known_bugs 5900c572928ec3b8c98c82fe4e95ebbe9aeee6c3 aubert@math.cnrs.fr 2020-05-15 18:19:36
Commit d8f62ded96991885a96d561db587988d453a28c8 - Added solution to second exam
Author: aubert@math.cnrs.fr
Author date (UTC): 2020-11-05 20:35
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2020-11-05 20:35
Parent(s): 7f48d88d2ed69213d803a7736df3d50330cfecd1
Signer:
Signing key:
Signing status: N
Tree: 1522613dd1bdf3986472064a498fdcd07a1b077d
File Lines added Lines deleted
notes/fig/er/cellphones.tex 82 0
notes/fig/er/template.def 1 0
notes/lectures_notes.md 155 0
File notes/fig/er/cellphones.tex added (mode: 100644) (index 0000000..863c28e)
1 \documentclass[border=20pt]{standalone}
2 \input{template.def}
3
4 \begin{tikzpicture}[node distance=1.5cm]
5 \node[entity] (SIMCARD) {SIMCARD};
6 \node[attribute] [above of=SIMCARD] {\key{ICCID}} edge (SIMCARD);
7 \node[attribute] [right = .5cm of SIMCARD] {IMSI} edge (SIMCARD);
8 \node[attribute] [above right = .5cm of SIMCARD] {Format} edge (SIMCARD);
9 %
10 \node[relationship] (STOREDIN) [left = 1.5cm of SIMCARD] {STORED\_IN} edge node[above, pos=0.4] {$\c1$} (SIMCARD);
11 %\node[attribute] [above = .3cm of STOREDIN] {URL} edge (STOREDIN);
12 %
13 \node[entity] (CONTACT) [left = 1.5cm of STOREDIN] {CONTACT} edge node[above, pos=0.6]{$\cM$} (STOREDIN);
14 \node[attribute] [above left of = CONTACT] {Email} edge (CONTACT);
15 \node[attribute] [left = .5cm of CONTACT] {Phone Number} edge (CONTACT);
16 \node[attribute] [below left = .5cm of CONTACT] {Name} edge (CONTACT);
17 \node[attribute] [above right of = CONTACT] {\key{id}} edge (CONTACT);
18 %
19 \node[relationship] (STOREDIN2) [below right = 1cm of CONTACT] {STORED\_IN} edge node[above, pos=0.4] {$\cM$} (CONTACT);
20 \node[attribute] [left = .3cm of STOREDIN2] {Picture} edge (STOREDIN2);
21 %
22 % \node[relationship] (EMPLOYS) [below =0.8cm of SIMCARD] {EMPLOYS} edge node[right, pos=0.4] {$\cN$} (SIMCARD);
23 %
24 \node[entity] (PHONE) [below left = 3cm and 2cm of SIMCARD] {PHONE} edge node[above, pos=0.6]{$\c1$} (STOREDIN2);
25 \node[multi attribute] [right = .5cm of PHONE] {IMEI} edge (PHONE);
26 \node[attribute] [left = .5cm of PHONE] {\key{Id}} edge (PHONE);
27 %
28 \node[relationship] (HELDBY) [below left = 1cm of SIMCARD] {HELD\_BY} edge node[above, pos=0.4] {$\cM$} (SIMCARD) edge node[above, pos=0.4] {$\c1$} (PHONE);
29 %
30
31 \node[entity] (OS) [below = 5cm of PHONE] {OS};
32 \node[attribute] [left = 0.5cm of OS] {\key{ID}} edge (OS);
33 \node[attribute] [below left = 0.5cm of OS] {Name} edge (OS);
34 \node[attribute] [below right = 0.5cm of OS] {Version} edge (OS);
35 \node[attribute] [below of = OS] {Licence} edge (OS);
36 %
37 \node[entity] (CN) [above left = 1cm and 5cm of OS] {CELLULAR\_NETWORK};
38 \node[attribute] [above of= CN] {\key{ID}} edge (CN);
39 \node[attribute] [below of= CN] {ITU Region} edge (CN);
40 \node[attribute] [left = .4cm of CN] {Band} edge (CN);
41
42 %
43 \node[relationship] [below left = 1cm and 2 cm of PHONE] {ACCESSIBLE\_TO} edge[total] node[above, pos=0.4] {$\cM$} (PHONE) edge node[above, pos=0.4] {$\cN$} (CN);
44 %
45 %
46 \node[entity] (App) [right = 5cm of OS] {APPLICATION};
47 ` \node[attribute] [right = 0.5cm of App] {\key{ID}} edge (App);
48 \node[attribute] [below left = 0.5cm of App] {Name} edge (App);
49 \node[attribute] [below right = 0.5cm of App] {Version} edge (App);
50 \node[attribute] [below of = App] {URL} edge (App);%
51
52 \node[relationship] [below = 1 cm of PHONE] {USES} edge[total] node[right, pos=0.4] {$\cM$} (PHONE) edge node[left]{$\cN$} (OS);
53
54 \node[relationship] [below right = 1.8cm and 1cm of PHONE] {IS\_COMPATIBLE\_WITH} edge node[right, pos=0.4] {$\cN$} (PHONE) edge node[above, pos=0.4] {$\cM$} (App) edge node[above, pos=0.4] {$\cM$}(OS);
55 % \node[relationship] (REPAIREDBY) [below right =3cm of PHONE] {REPAIRED\_BY} edge node[below, pos=0.6] {$\cM$} (PHONE) edge node[below, pos=0.6] {$1$} (PHONE);
56 %
57
58
59 %\node[entity] (SIMCARD) {SIMCARD};
60 %
61 %
62 %
63 %\node[relationship] (SPEAKS) [below right of=SIMCARD] {SPEAKS} edge node[right, pos=0.4] {$M$} (SIMCARD);
64 %\node[entity] (LANGUAGE) [below right of=SPEAKS] {LANGUAGE} edge node[right, pos=0.5] {$N$} (SPEAKS);
65 %\node[attribute] (code) [left of = LANGUAGE] {\key{Code}} edge (LANGUAGE);
66 %\node[attribute] (symbol) [right of = LANGUAGE] {Name} edge (LANGUAGE);
67 %
68 %\node[relationship] (BWF) [below of = LANGUAGE] {B\_W\_F};
69 %\draw (LANGUAGE) to node[left, pos=0.6] {$N$} (BWF.west);
70 %\draw (LANGUAGE) to node[right, pos=0.6] {$M$} (BWF.east);
71 %
72 %
73 %\node[multi attribute] (color) [right =1cm of anthem] {Creator} edge (anthem);
74
75 %
76 %\node[relationship] (WIN) [above right of =LANGUAGE] {W\_IN};
77 %\draw (LANGUAGE) to node[left, pos=0.6] {$N$} (WIN);
78 %\draw (anthem) to node[right, pos=0.6] {$M$} (WIN);
79
80 \end{tikzpicture}
81
82 \end{document}
File notes/fig/er/template.def changed (mode: 100644) (index 6f19033..6515dc0)
... ... every isa]
75 75 \newcommand{\cN}{\mathrm{N}} \newcommand{\cN}{\mathrm{N}}
76 76 \newcommand{\cO}{\mathrm{O}} \newcommand{\cO}{\mathrm{O}}
77 77 \newcommand{\cP}{\mathrm{P}} \newcommand{\cP}{\mathrm{P}}
78 \renewcommand{\c}[1]{\mathrm{#1}}
78 79
79 80 \begin{document} \begin{document}
File notes/lectures_notes.md changed (mode: 100644) (index 67184b4..53891a5)
... ... The quizzes are not indicated, but were generally a mix of up to five exercises
115 115 - Exam #1: - Exam #1:
116 116 - [%D %n (%T)](#problem:research-funding) - [%D %n (%T)](#problem:research-funding)
117 117 - [%D %n (%T)](#problem:rel_model_pet_shelter) - [%D %n (%T)](#problem:rel_model_pet_shelter)
118 - Exam #2:
119 - [%D %n (%T)](#problem:teaching)
120 - [%D %n (%T)](#problem:grade_report)
121 - [%D %n (%T)](#problem:cellphones)
122 - Five small exercises about [data base application](#exercises-4).
118 123
119 124 ### Spring 2020 {-} ### Spring 2020 {-}
120 125
 
... ... Problem (ER diagram for job and offers) +.#job-offers
6898 6903
6899 6904 --- ---
6900 6905
6906 Problem (ER diagram for cellphones) +.#cellphones
6907 ~
6908
6909 Draw an entity-relationship diagram for the following situation.
6910
6911 A sim card have a format (mini-SIM, micro-SIM, etc.) and unique ICCID and IMSI numbers.
6912 A cellular network have an ITU region and a frequency band.
6913 A phone has one or two IMEI number, can connect to one or multiple cellular networks, and can hold zero, one or two sim cards.
6914 A contact (which is made of a name, a phone number and an email) can be stored either in the sim card or in the phone (in which case you can add a picture to the contact).
6915 Every phone must have at least one operating system installed on it, and an operating system has a name, a version and licence.
6916 Finally, an application (which is made of a name, a version number and a url) may or may not be compatible with a phone / operating system pair.
6917
6918 ---
6919
6901 6920 Problem (Incorrect ER diagram) +.#incorrect-er Problem (Incorrect ER diagram) +.#incorrect-er
6902 6921 ~ ~
6903 6922
 
... ... Problem (From business statement to dependencies, ISP) +.#isp
7190 7209
7191 7210 --- ---
7192 7211
7212 Problem (Normal form for the GRADE\_REPORT Relation) +.#grade_report
7213 ~
7214
7215 Consider the following relation:
7216
7217 GRADE\_REPORT(StudentID, Term, StudentName, Address, Major, CourseID, CourseTitle, LetterGrade, Grade)
7218
7219 and the following functional dependencies:
7220
7221 ------------------------------------ ------- -------------
7222 StudentID $\to$ StudentName
7223 Major $\to$ Address
7224 {Major, CourseID} $\to$ CourseTitle
7225 Grade $\to$ LetterGrade
7226 {StudentID, Term, CourseID, Major} $\to$ Grade
7227 ------------------------------------ ------- -------------
7228
7229 Underline the primary key for that relation, then normalize it to the third normal form (you can indicate the second normal form if you want).
7230 Try to pick meaningful names for your relations.
7231
7232 ---
7233
7193 7234 Problem (Normalization) +.# Problem (Normalization) +.#
7194 7235 ~ ~
7195 7236
 
... ... Problem (A Relation for Network Cards) +.#network
7376 7417 #. Based on the functional dependencies you identified in the first step, is (are) the relation(s) you constructed in the second step in second normal form? #. Based on the functional dependencies you identified in the first step, is (are) the relation(s) you constructed in the second step in second normal form?
7377 7418 If yes, explain why, if no, normalize it (them). If yes, explain why, if no, normalize it (them).
7378 7419
7420
7421 ---
7422
7423 Problem (From Business Statement to Functional Dependencies to Normal Form -- TEACHING) +.#teaching
7424 ~
7425 This exercise asks you to convert business statements into dependencies, to identify a possible primary key, and to normalize the resulting relation.
7426
7427 Consider the following relation:
7428
7429 TEACHING(Class, Section, Instructor, Assistant, Office\_Hours, Meeting\_Hour)
7430
7431 - Write each of the following business statements as a functional
7432 dependency:
7433
7434 #. The meeting hour is determined by the class and section.
7435 #. An assistant is an assistant to an instructor, no matter the class or section.
7436 #. A section of a class is taught by one instructor ; different section of the same class can be taught by different instructors.
7437 #. The office hours depends of the instructor and class.
7438
7439 - Assuming all the functional dependencies you identified at the previous step hold, determine a suitable primary key for this
7440 relation.
7441
7442 - Taking the primary key you identified at the previous step, what is the degree of normality of this relation? Justify your answer.
7443
7444 - If needed, normalize this relation to the third normal form.
7445
7379 7446 --- ---
7380 7447
7381 7448 Problem (From ER to relational schema and UML class diagram -- CAR\_INFO) +.#carinfo Problem (From ER to relational schema and UML class diagram -- CAR\_INFO) +.#carinfo
 
... ... Solution to [%D %n (%T)](#problem:job-offers)
7503 7570
7504 7571 --- ---
7505 7572
7573 Solution to [%D %n (%T)](#problem:cellphones)
7574 ~
7575
7576 A possible solution is:
7577
7578 ![](fig/er/cellphones)
7579 \
7580
7581 Note that we sometimes introduced `ID` attributes, but could have done without as well (typically, by taking the name and version attributes and gathering them in the same attribute that could be used as a key, for the OS and APPLICATION entities).
7582
7583 ---
7584
7506 7585 Solution to [%D %n (%T)](#problem:incorrect-er) Solution to [%D %n (%T)](#problem:incorrect-er)
7507 7586 ~ ~
7508 7587
 
... ... Solution to [%D %n (%T)](#problem:isp)
7706 7785
7707 7786 --- ---
7708 7787
7788
7789
7790 Solution to [%D %n (%T)](#problem:grade_report)
7791 ~
7792
7793 The primary key would be \{StudentID, Term, Major, CourseID\}.
7794
7795 We obtain the following five relations when we normalize it to the third normal form:
7796
7797 GRADE\_REPORT(S͟t͟u͟d͟e͟n͟t͟I͟D͟, T͟e͟r͟m͟, C͟o͟u͟r͟s͟e͟I͟D͟, M͟a͟j͟o͟r͟, Grade)
7798 COURSE\_INFO(C͟o͟u͟r͟s͟e͟I͟D͟, M͟a͟j͟o͟r͟, CourseTitle)
7799 STUDENT\_INFO(S͟t͟u͟d͟e͟n͟t͟I͟D͟, StudentName)
7800 MAJOR\_INFO(M͟a͟j͟o͟r͟, Address)
7801 GRADE\_SCALE(G͟r͟a͟d͟e͟, LetterGrade)
7802
7803 ---
7804
7709 7805 Solution to [%D %n (%T)](#problem:book) Solution to [%D %n (%T)](#problem:book)
7710 7806 ~ ~
7711 7807
 
... ... Solution to [%D %n (%T)](#problem:coffeeNF)
7786 7882
7787 7883 --- ---
7788 7884
7885 Solution to [%D %n (%T)](#problem:teaching)
7886 ~
7887 - The functional dependencies given by the four statements are as follows:
7888
7889 | | |
7890 ---: | :---: | --- |
7891 \{Class, Section\} | → | Meeting\_Hour
7892 Assistant | → | Instructor
7893 \{Class, Section\} | → | Instructor
7894 \{Instructor, Class\} | → | Office\_Hours
7895
7896 Note that the statement reads "_An assistant is an assistant to an instructor_", which implies that an assistant can assist at most one instructor, but does not imply that an instructor can have at most one assistant: hence, the dependency is from Assistant to Instructor, and not the other way around.
7897
7898 - Based on the dependencies identified at the previous step, \{Class, Section, Assistant\} is the primary key.
7899
7900 - This relation is in 1st normal form: we make the assumption that all the attributes are atomic, and we identified a primary key. However, it is not in second normal form: Assistant → Instructor, for instance, makes that Instructor is not fully functionally dependent on the primary key.
7901
7902 - In third normal form, we would get:
7903
7904 CLASS\_INFO(C͟l͟a͟s͟s͟, S͟e͟c͟t͟i͟o͟n͟, Instructor, Meeting\_Hour)
7905 ASSISTANTSHIP(A͟s͟s͟i͟s͟t͟a͟n͟t͟, Instructor)
7906 OFFICE\_HOURS(I͟n͟s͟t͟r͟u͟c͟t͟o͟r͟, C͟l͟a͟s͟s͟, Office\_Hours)
7907
7908 ---
7909
7789 7910 Solution to [%D %n (%T)](#problem:carinfo) Solution to [%D %n (%T)](#problem:carinfo)
7790 7911 ~ ~
7791 7912
 
... ... Exercise +.#
8333 8454
8334 8455 Exercise +.# Exercise +.#
8335 8456
8457 : Why would somebody want to create multiple `Statement`{.java} objects?
8458
8459 Exercise +.#
8460
8336 8461 : What is the class of the object used to create a ResultSet object? : What is the class of the object used to create a ResultSet object?
8337 8462
8338 8463
 
... ... Exercise +.#
8384 8509 #. … the datatype of `strC`{.java}? #. … the datatype of `strC`{.java}?
8385 8510 #. … a possible value for `strC`{.java}? #. … a possible value for `strC`{.java}?
8386 8511
8512 Exercise +.#
8513 ~
8514 Let `stmt`{.java} be a statement object, and consider the following:
8515
8516 ``` {.java}
8517 ResultSet rset = stmt.executeQuery("SELECT Name, Price FROM DVD");
8518 ```
8519
8520 Write a piece of code that would display at the screen the name and price of the rows present in the `rset`{.java} object.
8387 8521
8388 8522 Exercise +.# Exercise +.#
8389 8523
8390 8524 : What is a prepared statement? : What is a prepared statement?
8391 8525
8526 Exercise +.#
8527
8528 : Give three reasons why prepared statements are preferable over statements.
8392 8529
8393 8530 Exercise +.# Exercise +.#
8394 8531
 
... ... Solution +.#
8433 8570
8434 8571 Solution +.# Solution +.#
8435 8572
8573 : You may want to create multiple `Statement`{.java} object for multiple reasons: to use parallelism (you could use a statement while another is still being processed), to have different policies (some objects could have update rights, some could not), to connect to multiple databases.
8574
8575 Solution +.#
8576
8436 8577 : The class of the object used to create a `ResultSet` object is the `Statement` class. A `Statement` object is used to create a `ResultSet` object, e.g. by calling the `executeQuery` method. : The class of the object used to create a `ResultSet` object is the `Statement` class. A `Statement` object is used to create a `ResultSet` object, e.g. by calling the `executeQuery` method.
8437 8578
8438 8579 Solution +.# Solution +.#
 
... ... Solution +.#
8476 8617
8477 8618 Solution +.# Solution +.#
8478 8619
8620 : We could use the following:
8621
8622 ```{.java}
8623 while(rset.next()){
8624 System.out.println("The name is " + rset.GetString("Name") + " and the price is " + rset.GetDouble("Price") + ".");
8625 }
8626 ```
8627
8628 Solution +.#
8629
8479 8630 : A prepared statement is a feature used to execute `SQL` statements repeatedly with high efficiency that protects against `SQL` injections. : A prepared statement is a feature used to execute `SQL` statements repeatedly with high efficiency that protects against `SQL` injections.
8480 8631
8632 Solution +.#
8633
8634 : A prepared statement offers a protection against `SQL` injection, mutualize the work (you write the query only once, and then re-use it), reduces the bandwith usage, and reduce the parsing time on the DBMS (the query is parsed only once as opposed to every time a statement is sent, no matter how similar to the previous one it is).
8635
8481 8636 Solution +.# Solution +.#
8482 8637 ~ ~
8483 8638
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/caubert/CSCI_3410

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/caubert/CSCI_3410

Clone this repository using git:
git clone git://git.rocketgit.com/user/caubert/CSCI_3410

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main