File notes/code/sql/HW_SocialMedia.sql added (mode: 100644) (index 0000000..3049161) |
|
1 |
|
/* code/sql/HW_SocialMedia.sql */ |
|
2 |
|
|
|
3 |
|
DROP SCHEMA IF EXISTS HW_SocialMedia; |
|
4 |
|
CREATE SCHEMA HW_SocialMedia; |
|
5 |
|
USE HW_SocialMedia; |
|
6 |
|
|
|
7 |
|
-- start snippet set-up |
|
8 |
|
CREATE TABLE ACCOUNT( |
|
9 |
|
ID INT PRIMARY KEY, |
|
10 |
|
Name VARCHAR(25), |
|
11 |
|
Email VARCHAR(25) UNIQUE |
|
12 |
|
); |
|
13 |
|
|
|
14 |
|
CREATE TABLE SUBSCRIBE( |
|
15 |
|
Subscriber INT, |
|
16 |
|
Subscribed INT, |
|
17 |
|
Date DATE, |
|
18 |
|
FOREIGN KEY (Subscriber) REFERENCES ACCOUNT(ID), |
|
19 |
|
FOREIGN KEY (Subscribed) REFERENCES ACCOUNT(ID), |
|
20 |
|
PRIMARY KEY (Subscriber, Subscribed) |
|
21 |
|
); |
|
22 |
|
|
|
23 |
|
CREATE TABLE VIDEO( |
|
24 |
|
ID INT PRIMARY KEY, |
|
25 |
|
Title VARCHAR(25), |
|
26 |
|
Released DATE, |
|
27 |
|
Publisher INT, |
|
28 |
|
FOREIGN KEY (Publisher) REFERENCES ACCOUNT(ID) |
|
29 |
|
); |
|
30 |
|
|
|
31 |
|
CREATE TABLE THUMBS_UP( |
|
32 |
|
Account INT, |
|
33 |
|
Video INT, |
|
34 |
|
Date DATE, |
|
35 |
|
PRIMARY KEY (Account, Video), |
|
36 |
|
FOREIGN KEY (Account) REFERENCES ACCOUNT(ID), |
|
37 |
|
FOREIGN KEY (Video) REFERENCES VIDEO(ID) |
|
38 |
|
); |
|
39 |
|
|
|
40 |
|
INSERT INTO ACCOUNT VALUES |
|
41 |
|
(1, "Bob Ross", "bob@ross.com"), |
|
42 |
|
(2, NULL, "anon@fai.com"), |
|
43 |
|
(3, "Martha", NULL); |
|
44 |
|
|
|
45 |
|
INSERT INTO SUBSCRIBE VALUES |
|
46 |
|
(2, 1, DATE"2020-01-01"), |
|
47 |
|
(3, 1, DATE"2019-03-03"), |
|
48 |
|
(3, 2, DATE"2019-03-03"), |
|
49 |
|
(2, 2, DATE"2019-03-03"), |
|
50 |
|
(1, 2, DATE"2019-03-03"); |
|
51 |
|
-- The first entry means that 2 subscribed to 1, not the other way around. |
|
52 |
|
-- And similarly for the other entries. |
|
53 |
|
|
|
54 |
|
INSERT INTO VIDEO VALUES |
|
55 |
|
(10, "My first video!", DATE"2020-02-02", 1), |
|
56 |
|
(20, "My second video!", DATE"2020-02-03", 1), |
|
57 |
|
(30, "My vacations", DATE"2020-02-04", 2); |
|
58 |
|
|
|
59 |
|
INSERT INTO THUMBS_UP VALUES |
|
60 |
|
(2, 10, DATE"2020-02-02"), |
|
61 |
|
(3, 10, DATE"2020-02-02"), |
|
62 |
|
(2, 20, DATE"2020-02-02"), |
|
63 |
|
(1, 30, DATE"2020-02-05"); |
|
64 |
|
|
|
65 |
|
-- end snippet set-up |
|
66 |
|
|
|
67 |
|
/* |
|
68 |
|
* |
|
69 |
|
* |
|
70 |
|
* Below are the solution, but think about it first! |
|
71 |
|
* |
|
72 |
|
* |
|
73 |
|
* |
|
74 |
|
*/ |
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
-- start snippet solution |
|
95 |
|
|
|
96 |
|
-- … the title of all the videos ("My first video!", "My second video!", "My vacations"). |
|
97 |
|
SELECT TITLE |
|
98 |
|
FROM VIDEO; |
|
99 |
|
|
|
100 |
|
-- … the release date of the video whose title is "My first video!" ("2020-02-02"). |
|
101 |
|
SELECT Released |
|
102 |
|
FROM VIDEO |
|
103 |
|
WHERE Title = "My first video!"; |
|
104 |
|
|
|
105 |
|
-- … the ID of the account(s) where the "Name" attribute was not given ("2"). |
|
106 |
|
SELECT ID |
|
107 |
|
FROM ACCOUNT |
|
108 |
|
WHERE Name IS NULL; |
|
109 |
|
|
|
110 |
|
-- … the ID of the videos whose title contains the word "video" ("10", "20"). |
|
111 |
|
SELECT ID |
|
112 |
|
FROM VIDEO |
|
113 |
|
WHERE TITLE LIKE "%video%"; |
|
114 |
|
|
|
115 |
|
-- or |
|
116 |
|
|
|
117 |
|
SELECT ID |
|
118 |
|
FROM VIDEO |
|
119 |
|
WHERE Title REGEXP 'video'; |
|
120 |
|
|
|
121 |
|
-- … the number of thumbs up for the video with title "My vacations" ("1"). |
|
122 |
|
SELECT COUNT(*) FROM THUMBS_UP, VIDEO |
|
123 |
|
WHERE VIDEO.Title="My vacations" |
|
124 |
|
AND |
|
125 |
|
VIDEO.ID = THUMBS_UP.Video; |
|
126 |
|
|
|
127 |
|
-- … the title of the oldest video ("My first video!"). |
|
128 |
|
SELECT Title |
|
129 |
|
FROM VIDEO |
|
130 |
|
WHERE Released <= ALL ( |
|
131 |
|
SELECT Released FROM VIDEO |
|
132 |
|
); |
|
133 |
|
|
|
134 |
|
-- or |
|
135 |
|
|
|
136 |
|
SELECT Title |
|
137 |
|
FROM VIDEO |
|
138 |
|
WHERE Released = ( |
|
139 |
|
SELECT Min(Released) FROM VIDEO |
|
140 |
|
); |
|
141 |
|
|
|
142 |
|
-- or even |
|
143 |
|
|
|
144 |
|
SELECT Title |
|
145 |
|
FROM VIDEO |
|
146 |
|
ORDER BY Released |
|
147 |
|
ASC LIMIT 1; |
|
148 |
|
|
|
149 |
|
-- … the names of the accounts who gave a thumbs up to the video with id 30 ("Bob Ross"). |
|
150 |
|
SELECT Name FROM ACCOUNT, THUMBS_UP |
|
151 |
|
WHERE THUMBS_UP.Video = 30 |
|
152 |
|
AND |
|
153 |
|
THUMBS_UP.Account = ACCOUNT.ID; |
|
154 |
|
|
|
155 |
|
-- … the ID of the account with the greatest number of subscribers ("2"). |
|
156 |
|
SELECT Subscribed |
|
157 |
|
FROM SUBSCRIBE |
|
158 |
|
GROUP BY Subscribed |
|
159 |
|
ORDER BY COUNT(Subscriber) DESC |
|
160 |
|
LIMIT 1; |
|
161 |
|
|
|
162 |
|
-- end snippet solution |
File notes/fig/er/incorrect.tex added (mode: 100644) (index 0000000..944fb65) |
|
1 |
|
\documentclass[border=20pt]{standalone} |
|
2 |
|
\input{template.def} |
|
3 |
|
|
|
4 |
|
\begin{tikzpicture}[node distance=1.5cm] |
|
5 |
|
\node[entity] (PROJECT) {PROJECT}; |
|
6 |
|
\node[attribute] [above of=PROJECT] {\key{Name}} edge (PROJECT); |
|
7 |
|
\node[attribute] [right = .5cm of PROJECT] {url} edge (PROJECT); |
|
8 |
|
\node[attribute] (leader) [above right = .5cm of PROJECT] {leader} edge (PROJECT); |
|
9 |
|
\node[attribute] [above right = .5cm of leader] {Name} edge (leader); |
|
10 |
|
\node[attribute] [right = .5cm of leader] {Email} edge (leader); |
|
11 |
|
% |
|
12 |
|
\node[ident relationship] (RECOMMENDEDBY) [left = 1.5cm of PROJECT] {RECOMMENDED\_BY} edge node[above, pos=0.4] {$1$} (PROJECT); |
|
13 |
|
% |
|
14 |
|
\node[weak entity] (GUIDELINES) [left = 1.5cm of RECOMMENDEDBY] {GUIDELINES} edge node[above, pos=0.6]{$\cM$} (RECOMMENDEDBY); |
|
15 |
|
\node[attribute] [above left = .5cm of GUIDELINES] {\pkey{url}} edge (GUIDELINES); |
|
16 |
|
\node[attribute] (ide) [left = 0.5cm of GUIDELINES] {Recommended IDE} edge (GUIDELINES); |
|
17 |
|
\node[attribute] (ide) [below left = 0.5cm of GUIDELINES] {Coding Style} edge (GUIDELINES); |
|
18 |
|
% |
|
19 |
|
\node[relationship] (USES) [below =1.5cm of PROJECT] {USES} edge (PROJECT); |
|
20 |
|
% |
|
21 |
|
\node[entity] (PROGRAMMINGLANGUAGE) [below = 5cm of PROJECT] {PROGRAMMING\_LANGUAGE} edge node[right, pos=0.4] {$1$} (USES); |
|
22 |
|
% \node[attribute] [right = .5cm of PROGRAMMINGLANGUAGE] {\key{Name}} edge (PROGRAMMINGLANGUAGE); |
|
23 |
|
\node[multi attribute] [below = .5cm of PROGRAMMINGLANGUAGE] {Version} edge (PROGRAMMINGLANGUAGE); |
|
24 |
|
\node[derived attribute] [below right = .5cm of PROGRAMMINGLANGUAGE] {Latest Version} edge (PROGRAMMINGLANGUAGE); |
|
25 |
|
% |
|
26 |
|
\node[entity] (PROGRAMMER) [below = 5cm of GUIDELINES] {PROGRAMMER};% edge node[right, pos=0.4] {$1$} (USES); |
|
27 |
|
\node[attribute] [left = .5cm of PROGRAMMER] {\key{Name}} edge (PROGRAMMER); |
|
28 |
|
\node[attribute] [below left = .5cm of PROGRAMMER] {\key{Email}} edge (PROGRAMMER); |
|
29 |
|
\node[attribute] [above left = .5cm of PROGRAMMER] {\key{id}} edge (PROGRAMMER); |
|
30 |
|
% |
|
31 |
|
\node[relationship] (KNOWS) [right =1.5cm of PROGRAMMER] {KNOWS} edge [total] node[above, pos=0.4] {$1$} (PROGRAMMINGLANGUAGE) edge [total] node[above, pos=0.4] {$\cM$} (PROGRAMMER); |
|
32 |
|
% |
|
33 |
|
% |
|
34 |
|
\node[relationship] (CONTRIBUTESTO) [above right =1.5cm of PROGRAMMER] {CONTRIBUTES\_TO} edge [total] node[above, pos=0.4] {$1$} (PROJECT) edge [total] node[above, pos=0.4] {$1$} (PROGRAMMER); |
|
35 |
|
% |
|
36 |
|
|
|
37 |
|
%\node[entity] (PROJECT) {PROJECT}; |
|
38 |
|
% |
|
39 |
|
% |
|
40 |
|
% |
|
41 |
|
%\node[relationship] (SPEAKS) [below right of=PROJECT] {SPEAKS} edge node[right, pos=0.4] {$M$} (PROJECT); |
|
42 |
|
%\node[entity] (LANGUAGE) [below right of=SPEAKS] {LANGUAGE} edge node[right, pos=0.5] {$N$} (SPEAKS); |
|
43 |
|
%\node[attribute] (code) [left of = LANGUAGE] {\key{Code}} edge (LANGUAGE); |
|
44 |
|
%\node[attribute] (symbol) [right of = LANGUAGE] {Name} edge (LANGUAGE); |
|
45 |
|
% |
|
46 |
|
%\node[relationship] (BWF) [below of = LANGUAGE] {B\_W\_F}; |
|
47 |
|
%\draw (LANGUAGE) to node[left, pos=0.6] {$N$} (BWF.west); |
|
48 |
|
%\draw (LANGUAGE) to node[right, pos=0.6] {$M$} (BWF.east); |
|
49 |
|
% |
|
50 |
|
% |
|
51 |
|
%\node[multi attribute] (color) [right =1cm of anthem] {Creator} edge (anthem); |
|
52 |
|
|
|
53 |
|
% |
|
54 |
|
%\node[relationship] (WIN) [above right of =LANGUAGE] {W\_IN}; |
|
55 |
|
%\draw (LANGUAGE) to node[left, pos=0.6] {$N$} (WIN); |
|
56 |
|
%\draw (anthem) to node[right, pos=0.6] {$M$} (WIN); |
|
57 |
|
|
|
58 |
|
\end{tikzpicture} |
|
59 |
|
|
|
60 |
|
\end{document} |
File notes/lectures_notes.md changed (mode: 100644) (index d83615e..84ef1b6) |
... |
... |
The quizzes are not indicated, but were generally a mix of up to five exercises |
123 |
123 |
|
|
124 |
124 |
### Spring 2020 {-} |
### Spring 2020 {-} |
125 |
125 |
|
|
|
126 |
|
Due to the Covid-19 pandemic, only one exam took place, and the final exam was taken remotely on D2L. |
|
127 |
|
A second project, more ambitious, was also asked from the students, and accounted for a large portion of their grade. |
|
128 |
|
|
126 |
129 |
- Project #1: [%D %n (%T)](#problem:project1) |
- Project #1: [%D %n (%T)](#problem:project1) |
127 |
130 |
- Exam #1: |
- Exam #1: |
128 |
131 |
- [%D %n (%T)](#problem:residency) |
- [%D %n (%T)](#problem:residency) |
129 |
132 |
- [%D %n (%T)](#problem:rel_model_auction_website) |
- [%D %n (%T)](#problem:rel_model_auction_website) |
|
133 |
|
- Final: |
|
134 |
|
- [%D %n (%T)](#problem:SocialMedia), where the last query was treated as a bonus, due to its difficulty. |
|
135 |
|
- [%D %n (%T)](#problem:explainNosql) |
|
136 |
|
- [%D %n (%T)](#problem:NormalizeDelivery) |
|
137 |
|
- [%D %n (%T)](#problem:incorrect-er) |
130 |
138 |
|
|
131 |
139 |
|
|
132 |
140 |
### Fall 2019 {-} |
### Fall 2019 {-} |
|
... |
... |
The quizzes are not indicated, but were generally a mix of up to five exercises |
159 |
167 |
- [%D %n (%T)](#problem:schedule) |
- [%D %n (%T)](#problem:schedule) |
160 |
168 |
- [%D %n (%T)](#problem:NormalizeMessage) |
- [%D %n (%T)](#problem:NormalizeMessage) |
161 |
169 |
- Final: |
- Final: |
162 |
|
- [%D %n (%T)](#problem:explainNosql) |
|
|
170 |
|
- A variation on [%D %n (%T)](#problem:explainNosql) |
163 |
171 |
- [%D %n (%T)](#problem:book) |
- [%D %n (%T)](#problem:book) |
164 |
172 |
- [%D %n (%T)](#problem:network) |
- [%D %n (%T)](#problem:network) |
165 |
173 |
- [%D %n (%T)](#problem:ComputerSelectBis) |
- [%D %n (%T)](#problem:ComputerSelectBis) |
|
... |
... |
Problem (Write select queries for the COMPUTER table) +.#ComputerSelect |
3810 |
3818 |
|
|
3811 |
3819 |
--- |
--- |
3812 |
3820 |
|
|
|
3821 |
|
Problem (Write select queries for the SocialMedia schema) +.#SocialMedia |
|
3822 |
|
~ |
|
3823 |
|
|
|
3824 |
|
Consider the following `SQL` code: |
|
3825 |
|
|
|
3826 |
|
```{.sqlmysql .numberLines include=code/sql/HW_SocialMedia.sql snippet=set-up} |
|
3827 |
|
``` |
|
3828 |
|
|
|
3829 |
|
Write queries that return the following information. The values returned *in this set-up* will be in parenthesis, but keep the queries general. |
|
3830 |
|
|
|
3831 |
|
#. The title of all the videos (`"My first video!"`, `"My second video!"`, `"My vacations"`). |
|
3832 |
|
#. The release date of the video whose title is `"My first video!"` (`"2020-02-02"`). |
|
3833 |
|
#. The ID of the account(s) where the "Name" attribute was not given (`"2"`). |
|
3834 |
|
#. The ID of the videos whose title contains the word `"video"` (`"10"`, `"20"`). |
|
3835 |
|
#. The number of thumbs up for the video with title `"My vacations"` (`"1"`). |
|
3836 |
|
#. The title of the oldest video (`"My first video!"`). |
|
3837 |
|
#. The names of the accounts who gave a thumbs up to the video with ID 30 (`"Bob Ross"`). |
|
3838 |
|
#. The ID of the account with the greatest number of subscribers (`"2"`). |
|
3839 |
|
|
|
3840 |
|
|
|
3841 |
|
--- |
|
3842 |
|
|
3813 |
3843 |
|
|
3814 |
3844 |
Problem (Write select queries for a variation of the COMPUTER table) +.#ComputerSelectBis |
Problem (Write select queries for a variation of the COMPUTER table) +.#ComputerSelectBis |
3815 |
3845 |
~ |
~ |
3816 |
3846 |
|
|
3817 |
3847 |
Consider the following `SQL` code: |
Consider the following `SQL` code: |
3818 |
3848 |
|
|
3819 |
|
```{.sqlmysql .numberLines include=code/sql/HW_ComputerVariation.sql} |
|
|
3849 |
|
```{.sqlmysql .numberLines include=code/sql/HW_ComputerVariation.sql snippet=set-up} |
3820 |
3850 |
``` |
``` |
3821 |
3851 |
|
|
3822 |
3852 |
Write queries that return the following information. The values returned *in this set-up* will be in parenthesis, but keep the queries general. |
Write queries that return the following information. The values returned *in this set-up* will be in parenthesis, but keep the queries general. |
|
... |
... |
Solution to [%D %n (%T)](#problem:ComputerSelectBis) |
4543 |
4573 |
|
|
4544 |
4574 |
~ |
~ |
4545 |
4575 |
|
|
|
4576 |
|
```{.sqlmysql .numberLines include=code/sql/HW_ComputerVariation.sql snippet=solution} |
4546 |
4577 |
``` |
``` |
4547 |
|
SELECT Model FROM COMPUTER WHERE ID = 'A'; |
|
4548 |
|
SELECT Type FROM PERIPHERAL WHERE ID = '14'; |
|
4549 |
|
SELECT Model FROM PERIPHERAL WHERE Type = 'printer'; |
|
4550 |
|
SELECT Model FROM PERIPHERAL WHERE Model LIKE 'IBM%'; |
|
4551 |
|
SELECT Model FROM PERIPHERAL, CONNEXION WHERE Computer = 'A' AND Peripheral = PERIPHERAL.ID; |
|
4552 |
|
SELECT COUNT(Computer) FROM CONNEXION, COMPUTER WHERE Model = 'Apple IIc Plus' AND Computer = COMPUTER.ID; |
|
|
4578 |
|
|
|
4579 |
|
--- |
|
4580 |
|
|
|
4581 |
|
Solution to [%D %n (%T)](#problem:SocialMedia) |
|
4582 |
|
~ |
|
4583 |
|
|
|
4584 |
|
```{.sqlmysql .numberLines include=code/sql/HW_SocialMedia.sql snippet=solution} |
4553 |
4585 |
``` |
``` |
4554 |
4586 |
|
|
|
4587 |
|
|
4555 |
4588 |
--- |
--- |
4556 |
4589 |
|
|
4557 |
4590 |
Solution to [%D %n (%T)](#problem:roleplaying) |
Solution to [%D %n (%T)](#problem:roleplaying) |
|
... |
... |
Problem (ER diagram for job and offers) +.#job-offers |
6626 |
6659 |
|
|
6627 |
6660 |
--- |
--- |
6628 |
6661 |
|
|
|
6662 |
|
Problem (Incorrect ER diagram) +.#incorrect-er |
|
6663 |
|
~ |
|
6664 |
|
|
|
6665 |
|
A company wants to develop a database to keep track of the programmers, projects and programming languages they know of. |
|
6666 |
|
They are not willing to store guidelines for the sake of it, but believe that if a project requires a particular guideline (like, which IDE to use, what spacing convention they use, etc.), it should be stored somewhere. |
|
6667 |
|
They want to accommodate the fact that a project can use multiple programming languages (and sometimes even multiple versions of the same language), and keep track of which programmer is leading which project. |
|
6668 |
|
To ease "match making", they also want to track which programmer is knowledgeable of what programming language. |
|
6669 |
|
They would also like to store links to the specifications of programming languages, as well as urls of the projects and their guidelines. |
|
6670 |
|
|
|
6671 |
|
They came up with the following ER diagram: |
|
6672 |
|
|
|
6673 |
|
 |
|
6674 |
|
\ |
|
6675 |
|
|
|
6676 |
|
|
|
6677 |
|
This diagram, to your expert eyes, has multiple flaws, missing constraints, and has some inconsistencies with their requirements. |
|
6678 |
|
List as many as you can, and suggest improvments or solution when you can think of one. |
|
6679 |
|
|
|
6680 |
|
|
|
6681 |
|
--- |
|
6682 |
|
|
6629 |
6683 |
Problem (Reverse engineering by hand) +.#Reverse-Engineering-ACTOR |
Problem (Reverse engineering by hand) +.#Reverse-Engineering-ACTOR |
6630 |
6684 |
~ |
~ |
6631 |
6685 |
|
|
|
... |
... |
Problem (From business statement to dependencies, ROUTE) +.#route |
6872 |
6926 |
A tuple in the ROUTE relation contains information about a public transportation route: its name (e.g. "Gold", "Green", …), its direction (e.g., "Medical Campus", "GCC", …), the fare zone where the route operates (e.g., "Zone 1", "Zone 2", …), the price of a ticket, the nature of the vehicles assuring the route (e.g., "subway", "bus", …) and the time of operations (e.g., "24 hours a day", "from 0600 to 2200", etc.). |
A tuple in the ROUTE relation contains information about a public transportation route: its name (e.g. "Gold", "Green", …), its direction (e.g., "Medical Campus", "GCC", …), the fare zone where the route operates (e.g., "Zone 1", "Zone 2", …), the price of a ticket, the nature of the vehicles assuring the route (e.g., "subway", "bus", …) and the time of operations (e.g., "24 hours a day", "from 0600 to 2200", etc.). |
6873 |
6927 |
|
|
6874 |
6928 |
#. Write each of the following business statement as a functional dependency: |
#. Write each of the following business statement as a functional dependency: |
6875 |
|
#. Two different types of vehicle can not operate on routes with the same name. |
|
|
6929 |
|
#. Two different types of vehicle can not operate on routes with the same name. |
6876 |
6930 |
#. The ticket price depends of the fare zone and the type of vehicule. |
#. The ticket price depends of the fare zone and the type of vehicule. |
6877 |
6931 |
#. Both the name and the direction are needed to determine the hours of operations. |
#. Both the name and the direction are needed to determine the hours of operations. |
6878 |
6932 |
#. Two routes with the same name and the same direction must have the same fare zone. |
#. Two routes with the same name and the same direction must have the same fare zone. |
|
... |
... |
Problem (Normal form of the BOOK relation) +.#book |
6940 |
6994 |
|
|
6941 |
6995 |
--- |
--- |
6942 |
6996 |
|
|
|
6997 |
|
Problem (Normal form of the DELIVERY relation) +.#NormalizeDelivery |
|
6998 |
|
~ |
|
6999 |
|
|
|
7000 |
|
Consider the following relation for deliveries: |
|
7001 |
|
|
|
7002 |
|
DELIVERY(Shipment, PackageNumber, RecipientName, Weight, DriverName, DriverPhone, RecipientPhone) |
|
7003 |
|
|
|
7004 |
|
Suppose we have the following functional dependencies: |
|
7005 |
|
|
|
7006 |
|
| | | |
|
7007 |
|
---: | :---: | --- | |
|
7008 |
|
Shipment | → | DriverName |
|
7009 |
|
PackageNumber | → | Shipment |
|
7010 |
|
PackageNumber | → | \{RecipientName, RecipientPhone\} |
|
7011 |
|
PackageNumber | → | Weight |
|
7012 |
|
DriverName | → | DriverPhone |
|
7013 |
|
|
|
7014 |
|
Answer the following three questions: |
|
7015 |
|
|
|
7016 |
|
#. Reply Yes / No to the following: In this model… |
|
7017 |
|
#. … can the shipment being handled by two drivers? |
|
7018 |
|
#. … can a package have two different recipient? |
|
7019 |
|
#. … can a package being in different shipments? |
|
7020 |
|
#. … can a recipient have two different phone numbers for the same name? |
|
7021 |
|
#. … can a driver have two different phone numbers for the same name? |
|
7022 |
|
#. Find a primary key for this relation. |
|
7023 |
|
#. Normalize this relation to the third normal form. |
|
7024 |
|
|
|
7025 |
|
--- |
|
7026 |
|
|
6943 |
7027 |
Problem (Normal form of the CONTACT relation) +.#NormalizeContact |
Problem (Normal form of the CONTACT relation) +.#NormalizeContact |
6944 |
7028 |
~ |
~ |
6945 |
7029 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:job-offers) |
7178 |
7262 |
|
|
7179 |
7263 |
--- |
--- |
7180 |
7264 |
|
|
|
7265 |
|
Solution to [%D %n (%T)](#problem:incorrect-er) |
|
7266 |
|
~ |
|
7267 |
|
|
|
7268 |
|
Among the numerous flaws, come to mind: |
|
7269 |
|
|
|
7270 |
|
#. "Technical errors" (making the diagram incorrect): |
|
7271 |
|
#. Multiple keys for an entity ("PROGRAMMER"), |
|
7272 |
|
#. Absence of a key ("PROGRAMMING\_LANGUAGE"), |
|
7273 |
|
#. Absence of the total participation constraint between the weak entity and its identifying relationship ("GUIDELINES" and "RECOMMENDED\_BY"), |
|
7274 |
|
#. Absence of an arity (between the "USES" relationship and the "PROJECT" entity), |
|
7275 |
|
#. To a certain extent, inconsistent naming (spaces / underscore, absence of capital letter for "leader" or "url") |
|
7276 |
|
#. Violations of the business statement: |
|
7277 |
|
#. "They want to accommodate the fact that a project can use multiple programming languages (and sometimes even multiple versions of the same language)": this is not possible. There are two ways of adding this feature: |
|
7278 |
|
#. Make the "PROGRAMMING\_LANGUAGE" entity become a "VERSION\_OF\_PROGRAMMING\_LANGUAGE" entity, and make the "USE" relationship M:N. |
|
7279 |
|
#. Leave the "PROGRAMMING\_LANGUAGE" entity as it is, make the "USE" relationship M:N, and add a "Version" attribute to it. |
|
7280 |
|
The first option being a bit more elegant, to some extend (but we lose the capacity of deriving the latest version). |
|
7281 |
|
#. "keep track of which programmer is leading which project.": As a leader is supposed to be a programmer as well, there should be a "IS\_THE\_LEADER\_OF" relationship between "PROGRAMMER" and "PROJECT", instead of an attribute on the "PROJECT" entity. |
|
7282 |
|
#. "they also want to track which programmer is knowledgeable of what programming language": the "KNOWS" relationship should not be "M:1", as a programmer can probably being knowledgeable in more than one programming language. |
|
7283 |
|
#. "if a project requires a particular guideline[…], it should be stored somewhere": The "RECOMMENDED\_BY" relationship should be 1:1. |
|
7284 |
|
#. Basic understanding errors: |
|
7285 |
|
#. The lack of "Name" attribute in the "PROGRAMMING\_LANGUAGE" entity is puzzling. |
|
7286 |
|
#. "CONTRIBUTES\_TO" should probably not being total on any side, as you may want to record programmers even if they are not contributing to any project, and project even if nobody is actively working on them. Also, it should not be 1:1, but M:N. |
|
7287 |
|
#. "RECOMMENDED\_BY" could probably be renamed "GUIDE\_THE\_DEVELOPMENT\_OF", for added clarity. |
|
7288 |
|
|
|
7289 |
|
|
|
7290 |
|
--- |
|
7291 |
|
|
7181 |
7292 |
Solution to [%D %n (%T)](#problem:ERtoRELBike) |
Solution to [%D %n (%T)](#problem:ERtoRELBike) |
7182 |
7293 |
~ |
~ |
7183 |
7294 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:book) |
7367 |
7478 |
|
|
7368 |
7479 |
--- |
--- |
7369 |
7480 |
|
|
|
7481 |
|
Solution to [%D %n (%T)](#problem:NormalizeDelivery) |
|
7482 |
|
~ |
|
7483 |
|
|
|
7484 |
|
#. Reply Yes / No to the following: In this model… |
|
7485 |
|
#. … can the shipment being handled by two drivers? **No** |
|
7486 |
|
#. … can a package have two different recipient? **No** |
|
7487 |
|
#. … can a package being in different shipments? **No** |
|
7488 |
|
#. … can a recipient have two different phone numbers for the same name? **Yes** |
|
7489 |
|
#. … can a driver have two different phone numbers for the same name? **No** |
|
7490 |
|
#. PackageNumber would be a suitable primary key for this relation. |
|
7491 |
|
#. A possible third normal form is (where the only functional dependencies are the one given by the primary keys): |
|
7492 |
|
SHIPMENT(S͟h͟i͟p͟m͟e͟n͟t͟, DriverName) |
|
7493 |
|
DRIVER(D͟r͟i͟v͟e͟r͟N͟a͟m͟e͟, DriverPhone) |
|
7494 |
|
PACKAGE(P͟a͟c͟k͟a͟g͟e͟N͟u͟m͟b͟e͟r͟, Shipment, Weight, RecipientName, RecipientNumber) |
|
7495 |
|
|
|
7496 |
|
--- |
|
7497 |
|
|
7370 |
7498 |
Solution to [%D %n (%T)](#problem:print) |
Solution to [%D %n (%T)](#problem:print) |
7371 |
7499 |
~ |
~ |
7372 |
7500 |
|
|
|
... |
... |
Problem (ER Diagram from XML File -- Award) +.#xmltoeraward |
9116 |
9244 |
|
|
9117 |
9245 |
## Solutions to Selected Problems {-} |
## Solutions to Selected Problems {-} |
9118 |
9246 |
|
|
|
9247 |
|
<!-- |
|
9248 |
|
|
|
9249 |
|
Solution to [%D %n (%T)](#problem:explainNosql) |
|
9250 |
|
~ |
|
9251 |
|
|
|
9252 |
|
#. |
|
9253 |
|
|
|
9254 |
|
#. |
|
9255 |
|
|
|
9256 |
|
#. |
|
9257 |
|
|
|
9258 |
|
--- |
|
9259 |
|
|
|
9260 |
|
--> |
|
9261 |
|
|
|
9262 |
|
|
9119 |
9263 |
Solution to [%D %n (%T)](#problem:xmltoercustomer) |
Solution to [%D %n (%T)](#problem:xmltoercustomer) |
9120 |
9264 |
~ |
~ |
9121 |
9265 |
|
|