List of commits:
Subject Hash Author Date (UTC)
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
Fixed contrib and enriched example. 04864c0ee2d4fa77b4e681ebf8049c4642bf1e67 aubert@math.cnrs.fr 2020-05-15 18:17:22
Fixed formatting mistake. 948a87c75b5d9aa8317feb5a0859d4efc23e95d6 aubert@math.cnrs.fr 2020-05-15 17:58:40
Cleaned SQL code. 4d39ebc5c1a3566ef4d3fa7afc8b2868f827c108 aubert@math.cnrs.fr 2020-05-15 17:41:00
Fixing few mistakes in code. b7eb7a0e476f8e0c3c6d3e651fd80827a03dd127 aubert@math.cnrs.fr 2020-05-15 17:38:32
Fixing few mistakes in code. 2bc77d7ee4e82e6961ce123fb7c3e1c68cba59b5 aubert@math.cnrs.fr 2020-05-15 17:30:02
Testing and indenting SQL code. a2b3bb4e242dd4980b94b25d11d6001459e2f0a0 aubert@math.cnrs.fr 2020-05-15 17:26:27
Clarified an example. e68bac453ab427c132b55249e21a08166b112f31 aubert@math.cnrs.fr 2020-05-15 15:06:54
Edits in style. 47578b081f74e9ec706772fa70a3079957129542 aubert@math.cnrs.fr 2020-05-15 14:38:16
Commit 7ad20b3c0025a4de3fa00729de570c6fe9176773 - Added solution to problem 2 of Exam #1.
Author: aubert@math.cnrs.fr
Author date (UTC): 2020-09-18 21:34
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2020-09-18 21:34
Parent(s): de427d78745593ab53dc70e7129b67fee1d4489c
Signer:
Signing key:
Signing status: N
Tree: 685cf82d8a0715616deea6ccfa203613128b6149
File Lines added Lines deleted
notes/fig/rel_mod/pet.tex 66 0
notes/lectures_notes.md 62 10
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 ![
1413 TYPE(Veterinarian(FK to VETERINARIAN.Id), Name (PK))
1414 VETERINARIAN (Name, Phone, Email, Address, Id (PK))
1415 ANIMAL (Name, ArrivalDate, FavoriteToy (FK to TOY.ID), Type (FK to TYPE.Name), Id (PK))
1416 TOY (Id (PK), Location, Description, Name, BestSuited (FK to TYPE.Name))
1417 ](fig/rel_mod/pet)
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).
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