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/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 |
|
 |
|
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 |
|
|