File notes/fig/rel_mod/pet.tex added (mode: 100644) (index 0000000..39886e5) |
|
1 |
|
\documentclass[border=20pt]{standalone} |
|
2 |
|
\input{template.def} |
|
3 |
|
|
|
4 |
|
% TYPE(Veterinarian(FK to VETERINARIAN.Id), Name (PK)) |
|
5 |
|
% VETERINARIAN (Name, Phone, Email, Address, Id (PK)) |
|
6 |
|
% ANIMAL (Name, ArrivalDate, FavoriteToy (FK to TOY.ID), Type (FK to TYPE.Name), Id (PK)) |
|
7 |
|
% TOY (Id (PK), Location, Description, Name, BestSuited (FK to TYPE.Name)) |
|
8 |
|
|
|
9 |
|
|
|
10 |
|
\Frame(0,0){1}[VETERINARIAN]{ |
|
11 |
|
Name/A, |
|
12 |
|
Phone/A, |
|
13 |
|
Email/A, |
|
14 |
|
Address/A, |
|
15 |
|
Id/PK}; |
|
16 |
|
|
|
17 |
|
\Frame(0,-2.5){2}[ANIMAL]{ |
|
18 |
|
Name/A, |
|
19 |
|
ArrivalDate/A, |
|
20 |
|
FavoriteToy/A, |
|
21 |
|
Type/A, |
|
22 |
|
Id/PK}; |
|
23 |
|
|
|
24 |
|
\Frame(0,-5){3}[TOY]{ |
|
25 |
|
Id/PK, |
|
26 |
|
Location/A, |
|
27 |
|
Description/A, |
|
28 |
|
Name/A, |
|
29 |
|
BestSuited/A, |
|
30 |
|
}; |
|
31 |
|
|
|
32 |
|
\Frame(8,0){4}[TYPE]{ |
|
33 |
|
Veterinarian/A, |
|
34 |
|
Name/PK}; |
|
35 |
|
|
|
36 |
|
\draw[FK] % From ANIMAL.FavoriteToy to TOY.Id |
|
37 |
|
(Id3) -- ++(0,-.55) -- ++(-1, 0) -- ++(0, 2.6) coordinate (inter) |
|
38 |
|
-- (FavoriteToy2 |- inter) --++(0, 0.5); |
|
39 |
|
|
|
40 |
|
\draw[FK] % From TYPE.Veterinarian to VETERINARIAN.Id |
|
41 |
|
(Id1) -- ++(0,-.55) coordinate (inter) |
|
42 |
|
-- (Veterinarian4 |- inter) --++(0, 0.5); |
|
43 |
|
|
|
44 |
|
\draw[FK] % From ANIMAL.Type to TYPE.Name |
|
45 |
|
(Name4)++(0.1, 0) -- ++(0,-5.5) coordinate (inter) |
|
46 |
|
-- (BestSuited3 |- inter) --++(0, 0.5); |
|
47 |
|
|
|
48 |
|
\draw[FK] % From ANIMAL.Type to TYPE.Name |
|
49 |
|
(Name4)++(-0.1, 0) -- ++(0,-3) coordinate (inter) |
|
50 |
|
-- (Type2 |- inter) --++(0, 0.5); |
|
51 |
|
% |
|
52 |
|
|
|
53 |
|
%\draw[FK] % From TYPE.ANIMAL to ANIMAL.Id |
|
54 |
|
%(Id2)++(0.2,0) -- ++(0,-0.6) |
|
55 |
|
%coordinate (inter) -- (ANIMAL4 |- inter) --(ANIMAL4); |
|
56 |
|
% |
|
57 |
|
%\draw[FK] % From TOY.Sponsor to ANIMAL.Id |
|
58 |
|
%(Id2)++(-0.1,0) --++ (0, -0.6) -- ++(-7,0) -- ++(0, 2.5) |
|
59 |
|
%coordinate (inter) -- (Sponsor1 |- inter) --(Sponsor1); |
|
60 |
|
% |
|
61 |
|
%\draw[FK] % From REPRESENTATIVES.ANIMAL to ANIMAL.Id |
|
62 |
|
%(Id2)++(0.05,0) --++ (0, -3) |
|
63 |
|
%coordinate (inter) -- (ANIMAL3 |- inter) --(ANIMAL3) --++ (0, 0.1); |
|
64 |
|
|
|
65 |
|
\end{tikzpicture} |
|
66 |
|
\end{document} |
File notes/lectures_notes.md changed (mode: 100644) (index bbdc8de..94b7beb) |
... |
... |
pandoc-numbering: |
37 |
37 |
## How to Use This Guide {-} |
## How to Use This Guide {-} |
38 |
38 |
|
|
39 |
39 |
These lecture notes are written in an elusive style: they are a support for the explanations that will be made at the board. |
These lecture notes are written in an elusive style: they are a support for the explanations that will be made at the board. |
40 |
|
They are not designed to be self-contained: they are rather a list of topics and reminders, along with handy examples, code and drawings. |
|
|
40 |
|
<!-- They are not designed to be self-contained: they are rather a list of topics and reminders, along with handy examples, code and drawings. --> |
41 |
41 |
Reading them before coming to the lecture will help you getting a sense of the next topic we will be discussing, but you may sometimes have trouble deciphering their … *unique* style. |
Reading them before coming to the lecture will help you getting a sense of the next topic we will be discussing, but you may sometimes have trouble deciphering their … *unique* style. |
42 |
42 |
|
|
43 |
43 |
When it comes to code, you can normally copy-and-paste it from the document and use it as it is. |
When it comes to code, you can normally copy-and-paste it from the document and use it as it is. |
|
... |
... |
Problem (Relational model for an auction website) +.#rel_model_auction_website |
1317 |
1317 |
When creating your schema, do not add any new information, and try as much as possible to avoid relations that will create redundant data and `NULL` entries. |
When creating your schema, do not add any new information, and try as much as possible to avoid relations that will create redundant data and `NULL` entries. |
1318 |
1318 |
Note that we should be able to uniquely determine the member account linked to the seller account, and similarly for buyers accounts. |
Note that we should be able to uniquely determine the member account linked to the seller account, and similarly for buyers accounts. |
1319 |
1319 |
Furthermore, members can have at most one buyer and one seller account. |
Furthermore, members can have at most one buyer and one seller account. |
1320 |
|
|
|
|
1320 |
|
|
|
1321 |
|
--- |
|
1322 |
|
|
|
1323 |
|
Problem (Relational model for a pet shelter) +.#rel_model_pet_shelter |
|
1324 |
|
~ |
|
1325 |
|
|
|
1326 |
|
We want to design a relational model for an animal shelter, with three goals in mind: to keep track of the pets currently sheltered, of the veterinarian for each type of pet, and of each pet's favorite toy (needed during a visit to the veterinarian!). |
|
1327 |
|
|
|
1328 |
|
Follow the specification below: |
|
1329 |
|
|
|
1330 |
|
- An animal has a type (cat, fish, dog, etc.), an arrival date, a name, and an id number. |
|
1331 |
|
- Every type of animal has a veterinarian. |
|
1332 |
|
- A veterinarian has a name, a phone number, an email address, and a postal address. |
|
1333 |
|
- Multiple types of animals can have the same veterinarian. |
|
1334 |
|
- A toy has a location, a description, a name, and is best suited for a particular type of animal. |
|
1335 |
|
- Each animal has at most one preferred toy. |
|
1336 |
|
|
|
1337 |
|
When creating your schema (that you can draw at the back of previous page), do not add any new information (except possibly "id" attributes), and try as much as possible to avoid relations that will create redundant data and `NULL`{.sql} entries. Identify the primary key for each relation that you create. When you are done, answer the true / false question below. |
|
1338 |
|
|
|
1339 |
|
With your model … | Yes | No |
|
1340 |
|
------------------- | --- | --- |
|
1341 |
|
…it is possible to determine which pet don't have a favorite toy. | | |
|
1342 |
|
…it is possible to determine what is the average stay in the shelter. | | |
|
1343 |
|
…it is possible to determine if a pet's favorite toy is best suited for their type. | | |
|
1344 |
|
…it is possible for multiple types of animal to have the same veterinarian. | | |
|
1345 |
|
…it is possible for multiple veterinarians to be attributed to the same type. | | |
|
1346 |
|
|
|
1347 |
|
--- |
|
1348 |
|
|
1321 |
1349 |
## Solutions to Selected Problems {-} |
## Solutions to Selected Problems {-} |
1322 |
1350 |
|
|
1323 |
1351 |
Solution to [%D %n (%T)](#problem:cinema) |
Solution to [%D %n (%T)](#problem:cinema) |
|
... |
... |
OFFERING (Department (PK, FK to DEPARTMENT.Name), Course (PK, FK to COURSE.Name) |
1372 |
1400 |
](fig/rel_mod/universities) |
](fig/rel_mod/universities) |
1373 |
1401 |
\ |
\ |
1374 |
1402 |
|
|
|
1403 |
|
--- |
|
1404 |
|
|
|
1405 |
|
Solution to [%D %n (%T)](#problem:rel_model_pet_shelter) |
|
1406 |
|
|
|
1407 |
|
~ |
|
1408 |
|
|
|
1409 |
|
A possible solution follows. |
|
1410 |
|
|
|
1411 |
|
|
|
1412 |
|
 |
|
1418 |
|
\ |
|
1419 |
|
|
|
1420 |
|
In this model, |
|
1421 |
|
…it **is** possible to determine which pet don't have a favorite toy. |
|
1422 |
|
…it **is not** possible to determine what is the average stay in the shelter, _because their exit date is not stored._ |
|
1423 |
|
…it **is** possible to determine if a pet's favorite toy is best suited for their type. |
|
1424 |
|
…it **is** possible for multiple types of animal to have the same veterinarian, _as the same value for "Veterinarian" could occur in multiple tuples in the TYPE relation. If both "Veterinarian" and "Name" were parts of the primary key, then that would not be the case._ |
|
1425 |
|
…it **is not** possible for multiple veterinarians to be attributed to the same type, _as the name of the type is the primary key in the TYPE relation._ |
|
1426 |
|
|
1375 |
1427 |
|
|
1376 |
1428 |
# The SQL Programming Language |
# The SQL Programming Language |
1377 |
1429 |
|
|
|
... |
... |
Problem (A simple database for published pieces of work) +.#sqlWorks |
3984 |
4036 |
@problem:sqlWorks -- Question -.# |
@problem:sqlWorks -- Question -.# |
3985 |
4037 |
~ |
~ |
3986 |
4038 |
|
|
3987 |
|
Determine if the following insertion statements would violate the the entity integrity constraint, the referential integrity constraint, if there would be some other kind of error, or if it would result in sunsuccessful insertion. |
|
|
4039 |
|
Determine if the following insertion statements would violate the entity integrity constraint, the referential integrity constraint, if there would be some other kind of error, or if it would result in successful insertion. |
3988 |
4040 |
|
|
3989 |
4041 |
``` |
``` |
3990 |
4042 |
INSERT INTO EBOOK VALUES (0, NULL, 20180101, 0); |
INSERT INTO EBOOK VALUES (0, NULL, 20180101, 0); |
|
... |
... |
Problem (A database for residencies) +.#residency |
4133 |
4185 |
: Write a command that violates the referential integrity constraint. |
: Write a command that violates the referential integrity constraint. |
4134 |
4186 |
|
|
4135 |
4187 |
@problem:residency -- Question -.# |
@problem:residency -- Question -.# |
4136 |
|
: List the rows (`"P.2, H.1, or "none""'{'sqlmysql}) modified by the following statements: |
|
|
4188 |
|
: List the rows (e.g. "P.2", "H.1", or "none") modified by the following statements: |
4137 |
4189 |
|
|
4138 |
4190 |
#. `UPDATE HOUSE SET COLOR = "green";` |
#. `UPDATE HOUSE SET COLOR = "green";` |
4139 |
4191 |
#. `DELETE FROM RESIDENCY WHERE House LIKE "1%";` |
#. `DELETE FROM RESIDENCY WHERE House LIKE "1%";` |
|
... |
... |
Exercise +.# |
8203 |
8255 |
```{.java} |
```{.java} |
8204 |
8256 |
modif = stmt.executeUpdate(strC); |
modif = stmt.executeUpdate(strC); |
8205 |
8257 |
``` |
``` |
8206 |
|
What is... |
|
|
8258 |
|
What is… |
8207 |
8259 |
|
|
8208 |
|
#. ... the datatype of `modif`{.java}? |
|
8209 |
|
#. ... the datatype of `strC`{.java}? |
|
8210 |
|
#. ... a possible value for `strC`{.java}? |
|
|
8260 |
|
#. … the datatype of `modif`{.java}? |
|
8261 |
|
#. … the datatype of `strC`{.java}? |
|
8262 |
|
#. … a possible value for `strC`{.java}? |
8211 |
8263 |
|
|
8212 |
8264 |
|
|
8213 |
8265 |
Exercise +.# |
Exercise +.# |
|
... |
... |
Solution +.# |
8246 |
8298 |
|
|
8247 |
8299 |
Solution +.# |
Solution +.# |
8248 |
8300 |
|
|
8249 |
|
: It is important to put the statements that create the connection to the database inside the `try...catch`{.java} statement because the program will interact with the environment if this interraction fails (typically, if the connection does not succeed), for which we want to be able to catch the exception and recover from that failure. |
|
|
8301 |
|
: It is important to put the statements that create the connection to the database inside the `try…catch`{.java} statement because the program will interact with the environment if this interraction fails (typically, if the connection does not succeed), for which we want to be able to catch the exception and recover from that failure. |
8250 |
8302 |
|
|
8251 |
8303 |
Solution +.# |
Solution +.# |
8252 |
8304 |
|
|
|
... |
... |
Solution +.# |
8293 |
8345 |
|
|
8294 |
8346 |
Solution +.# |
Solution +.# |
8295 |
8347 |
|
|
8296 |
|
: In the statement `modif = stmt.executeUpdate(strC);`{.java}... |
|
|
8348 |
|
: In the statement `modif = stmt.executeUpdate(strC);`{.java}… |
8297 |
8349 |
|
|
8298 |
8350 |
#. `modif` is an integer (the number of rows modified by the query). |
#. `modif` is an integer (the number of rows modified by the query). |
8299 |
8351 |
#. `strC` is a `String` (a `SQL` command). |
#. `strC` is a `String` (a `SQL` command). |