List of commits:
Subject Hash Author Date (UTC)
Adding quiz #2, correcting a few typo in SQL chapter. 16e6aee0be154245b472c77fb2d6a486dd07ef38 aubert@math.cnrs.fr 2019-09-16 19:58:53
Quick changes in the first SQL part: check is actually taken into account! b62ed769ef0ebd96ea91e3053246e142b73d524c aubert@math.cnrs.fr 2019-09-09 16:26:17
Added quiz #1 of Fall 2019, plus minor corrections. a5498523b05cb246ce58b05a8951b833a0b0e699 aubert@math.cnrs.fr 2019-08-29 16:23:07
Adding a figure for a quizz, and a possible bug to the list. 6e83297ccb9678296993e605b2f35d0b13a97523 aubert@math.cnrs.fr 2019-08-27 16:20:35
Changed the monospace font, updated instructions to install mariaDB. 3dc6162733e0a373205012869c1ee068ef3e5c91 aubert@math.cnrs.fr 2019-08-16 18:56:37
Few patches to prepare for Fall 2019. 545561b3d47dfe9bff2436f8f2b7e32572cd808a aubert@math.cnrs.fr 2019-08-07 17:12:26
Editing the cycle of design picture 9bd1c3190a71202b88011b831161cf9d6a365237 aubert@math.cnrs.fr 2019-08-07 16:13:03
Test c742ba7590d59e2941f9fa197c9d009d5c642e76 au 2019-07-31 23:56:14
Minor fix in Known bugs and contrib. 19f3adfa1f88e6d12e94868f4eab0b5838d05eb6 aubert@math.cnrs.fr 2019-07-29 20:51:14
Commit 2ed1a8532cbdae46d3feb99cf52f23f2afa144ec aubert@math.cnrs.fr 2019-07-29 19:01:36
Adding the final to the notes. 0e8848a3e67ec49bab5b767e25d6099fd218e417 aubert@math.cnrs.fr 2019-05-20 14:44:54
Added the solution to one of the problem from Exam #2. 625545a335c5dc7b7303355088a3abba999fdf40 aubert@math.cnrs.fr 2019-05-06 16:59:50
Added a solution to one of the problem of Exam #2, and added the last quiz. 4e0ee25d509412e5e455d9ad4c98f7aad8c5a354 aubert@math.cnrs.fr 2019-04-19 15:14:10
A few glitches in the first java programs patched, added the alternative version to the source. 48611244d21515269bae041dc2535b7e08fb5877 aubert@math.cnrs.fr 2019-04-04 22:05:03
patching a few glitches with the java code and the mysql code used in the demo for the first program. 0fcb73dcc60aef476899c4efea092c99dd6027db aubert@math.cnrs.fr 2019-04-04 21:55:55
Tidying up a program. dd409ab3fd6736af4b8adaac284ee101b9770f60 aubert@math.cnrs.fr 2019-04-04 19:02:21
Correcting the chapter on db programming. 484c4a6372056106bae77e48b397c1174738fc26 aubert@math.cnrs.fr 2019-04-04 18:57:50
Added solution to first problem of Exam 2. 45881a9b8ab1e5a0071b58d72362059593365d52 aubert@math.cnrs.fr 2019-04-03 18:38:48
Quick note in Java programming. 625282d4fece1f6a7a617a8c9bcf7c3c856185b3 aubert@math.cnrs.fr 2019-04-02 18:42:48
Added exam #2 0aa6788451b34cb6371fed5a0f719a4ac52cf0c8 aubert@math.cnrs.fr 2019-04-01 18:37:43
Commit 16e6aee0be154245b472c77fb2d6a486dd07ef38 - Adding quiz #2, correcting a few typo in SQL chapter.
Author: aubert@math.cnrs.fr
Author date (UTC): 2019-09-16 19:58
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2019-09-16 19:58
Parent(s): b62ed769ef0ebd96ea91e3053246e142b73d524c
Signing key:
Tree: 418131392454ff317c450d88bb49fa5e654f34ee
File Lines added Lines deleted
notes/code/sql/SIMPLE_BOOK.sql 1 2
notes/lectures_notes.md 87 22
notes/temp.md 2 3
File notes/code/sql/SIMPLE_BOOK.sql changed (mode: 100644) (index 0855f02..16ecedd)
... ... code/sql/SIMPLE_BOOK.sql
4 4
5 5 The following is in case you want to run your program on your installation: The following is in case you want to run your program on your installation:
6 6
7 DROP SCHEMA IF EXISTS HW_SIMPLE_BOOK;
7 8 CREATE SCHEMA HW_SIMPLE_BOOK; CREATE SCHEMA HW_SIMPLE_BOOK;
8 9 USE HW_SIMPLE_BOOK; USE HW_SIMPLE_BOOK;
9
10 10 */ */
11 11
12 12 CREATE TABLE AUTHOR( CREATE TABLE AUTHOR(
File notes/lectures_notes.md changed (mode: 100644) (index 4aee7dc..ddb262f)
... ... SELECT Name FROM PROF
1729 1729 WHERE Login LIKE '_aubert'; WHERE Login LIKE '_aubert';
1730 1730 ~~~ ~~~
1731 1731
1732 Note that `LIKE` is by default case-insensitive, both in [MariaDB](https://mariadb.com/kb/en/library/like/) and in [MySQL](https://dev.mysql.com/doc/refman/8.0/en/case-sensitivity.html).
1733 The `COLLATE` operator can be used to force the search to be case-sensitive.
1734
1732 1735 --- ---
1733 1736
1734 1737
 
... ... SELECT Fellow.Name AS 'Fellow of Ava'
1985 1988 FROM STUDENT AS Me, STUDENT AS Fellow FROM STUDENT AS Me, STUDENT AS Fellow
1986 1989 WHERE Me.Name = 'Ava Alyx' WHERE Me.Name = 'Ava Alyx'
1987 1990 AND Fellow.Major = Me.Major AND Fellow.Major = Me.Major
1988 AND NOT Fellow.Name = 'Ava Alyx';
1991 AND NOT Fellow.Name = Me.Name;
1989 1992 ~~~ ~~~
1990 1993
1991 1994 `AND NOT Me = Fellow` would *not* work. `AND NOT Me = Fellow` would *not* work.
 
... ... A nested query is made of an outer query (`SELECT Login`…) and an inner query
2007 2010 SELECT Login FROM GRADE SELECT Login FROM GRADE
2008 2011 WHERE Grade >= WHERE Grade >=
2009 2012 ALL (SELECT Grade FROM GRADE WHERE Grade IS NOT NULL); ALL (SELECT Grade FROM GRADE WHERE Grade IS NOT NULL);
2013 ~~~
2014
2015 Note that this query could be simplified, using `MAX`:
2016
2017 ~~~{.sqlmysql .numberLines}
2018 SELECT Login FROM GRADE
2019 WHERE Grade >=
2020 (SELECT MAX(Grade) FROM GRADE);
2021 ~~~
2010 2022
2023 ~~~{.sqlmysql .numberLines}
2011 2024 SELECT Login SELECT Login
2012 2025 FROM PROF FROM PROF
2013 2026 WHERE DEPARTMENT IN ( SELECT Major WHERE DEPARTMENT IN ( SELECT Major
 
... ... After that last command, you should see
2356 2369 ~~~ ~~~
2357 2370
2358 2371
2359 Finally, we can erasre the content of the table, then erase ("drop") the table, and finally the schema:
2372 Finally, we can erase the content of the table, then erase ("drop") the table, and finally the schema:
2360 2373
2361 2374 ~~~{.sqlmysql} ~~~{.sqlmysql}
2362 2375 DELETE FROM TableTest; -- Delete the rows DELETE FROM TableTest; -- Delete the rows
 
... ... EXIT;
2372 2385
2373 2386 ## Exercises {-} ## Exercises {-}
2374 2387
2388 Exercise +.#
2389 ~
2390
2391 For each of the following, fill in the blanks:
2392
2393 - In `SQL`, a relation is called a ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ .
2394 - In `SQL`, every statement ends with ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟, and in-line comments start with a ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ .
2395 - In `SQL`, there is no `string` datatype, so we have to use ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟.
2396 - The Data Control Language of `SQL`'s role is to ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ ͟ .
2397
2375 2398 Exercise +.# Exercise +.#
2376 2399
2377 2400 : What does it mean to say that `SQL` is at the same time a "data definition language" and a "data manipulation language"? : What does it mean to say that `SQL` is at the same time a "data definition language" and a "data manipulation language"?
 
... ... Exercise +.#
2406 2429
2407 2430 : Explain this query: `CREATE SCHEMA FACULTY;`{.sqlmysql}. : Explain this query: `CREATE SCHEMA FACULTY;`{.sqlmysql}.
2408 2431
2432 Exercise +.#explainsql
2433 ~
2434
2435 Write code to
2436
2437 - declare a first table with two attributes, one of which is the primary key,
2438 - declare a second table with two attributes, one of which is the primary key, and the other references the primary key of the first table,
2439 - insert one tuple in the first table,
2440 - insert one tuple in the second table, referencing the only tuple of the first table,
2441
2442 You are free to come up with an example (even very simple or cryptic) or to re-use an example from class.
2443
2444
2409 2445 Exercise +.#explainsql Exercise +.#explainsql
2410 2446 ~ ~
2411 2447
 
... ... Exercise +.#twice_row_sql
2603 2639
2604 2640 : Under which conditions does `SQL` allow you to enter the same row in a table twice? : Under which conditions does `SQL` allow you to enter the same row in a table twice?
2605 2641
2606 #### Exercises {-}
2607
2608 2642 ## Solution to Exercises {-} ## Solution to Exercises {-}
2609 2643
2644
2645 Solution +.#
2646 ~
2647 The blanks can be filled as follow:
2648
2649 - In `SQL`, a relation is called a ͟ ͟ ͟ ͟table ͟ ͟ ͟ ͟ ͟ ͟ ͟ .
2650 - In `SQL`, every statement ends with ͟ ͟a semi-colon (`;`) ͟ ͟, and in-line comments start with a ͟ ͟ ͟two minus signs (`--`) ͟ ͟ .
2651 - In `SQL`, there is no `string` datatype, so we have to use ͟ ͟ ͟VARCHAR(x) or CHAR(x) where x is an integer reflecting the maximum (or fixed) size of the string ͟ ͟ ͟ ͟ ͟ .
2652 - The Data Control Language of `SQL`'s role is to ͟ ͟ control access to the data stored, by creating users and granting them rights ͟ ͟ .
2653
2610 2654 Solution +.# Solution +.#
2611 2655
2612 2656 : It can specify the conceptual and internal schema, **and** it can manipulate the data. : It can specify the conceptual and internal schema, **and** it can manipulate the data.
 
... ... Solution +.#
2639 2683
2640 2684 : It creates a schema, i.e., a database, named `Faculty`{.sqlmysql}. : It creates a schema, i.e., a database, named `Faculty`{.sqlmysql}.
2641 2685
2686 Solution +.#
2687 ~
2688 A simple and compact code could be:
2689
2690 ~~~{.sqlmysql}
2691 -- You can ignore the first three lines.
2692 DROP SCHEMA IF EXISTS HW_SHORT;
2693 CREATE SCHEMA HW_SHORT;
2694 USE HW_SHORT;
2695 CREATE TABLE A(Att1 INT PRIMARY KEY, Att2 INT);
2696 CREATE TABLE B(Att3 INT PRIMARY KEY, Att4 INT, FOREIGN KEY (Att4) REFERENCES A(Att1));
2697 INSERT INTO A VALUES (1, 2);
2698 INSERT INTO B VALUES (3, 1);
2699 ~~~~
2700
2642 2701 Solution +.# Solution +.#
2643 2702
2644 2703 : It removes the `UNIQUE`{.sqlmysql} constraint on the `Attribute1`{.sqlmysql} in the `TABLEA`{.sqlmysql} table. : It removes the `UNIQUE`{.sqlmysql} constraint on the `Attribute1`{.sqlmysql} in the `TABLEA`{.sqlmysql} table.
 
... ... Solution +.#
2763 2822 - `FALSE AND UNKNOWN`{.sqlmysql} → `FALSE`{.sqlmysql} - `FALSE AND UNKNOWN`{.sqlmysql} → `FALSE`{.sqlmysql}
2764 2823 - The other cases can be deduced by symmetry. - The other cases can be deduced by symmetry.
2765 2824
2766 For a more compact presentation, refer to (#truth-tables).
2825 For a more compact presentation, refer to [the three-valued truth table"](#truth-tables).
2767 2826
2768 2827 Solution +.# Solution +.#
2769 2828
 
... ... Solution +.#
2799 2858
2800 2859 Solution +.# Solution +.#
2801 2860
2802 : Essentially, if there are no primary key in the relation, and if no attribute has the `UNIQUE`{.sqlmysql} constraint. Cf. also [%D %n (%T)](#problem:repetition).
2803
2861 : Essentially, if there are no primary key in the relation, and if no attribute has the `UNIQUE`{.sqlmysql} constraint. Cf. also [this previous problem](#problem:repetition).
2862 <!--
2863 Bug.
2864 Link to Duplicate rows in SQL
2865 For some reason,
2866 [%D %n (%T)](#problem:repetition).
2867 does not work as intended.
2868 -->
2804 2869
2805 2870 ## Problems {-} ## Problems {-}
2806 2871
 
... ... Problem (A simple database for books) +.#sqlBooks
3351 3416 ## Solution to Selected Problems {-} ## Solution to Selected Problems {-}
3352 3417
3353 3418
3354 Solution to [%D %n (%T)](#problem:ComputerSelectBis)
3355
3356 ~
3357
3358 ~~~{.sqlmysql}
3359 SELECT Model FROM COMPUTER WHERE Id = 'A';
3360 SELECT Type FROM PERIPHERAL WHERE Id = '14';
3361 SELECT Model FROM PERIPHERAL WHERE Type = 'printer';
3362 SELECT Model FROM PERIPHERAL WHERE Model LIKE 'IBM%';
3363 SELECT Model FROM PERIPHERAL, CONNEXION WHERE Computer = 'A' AND Peripheral = PERIPHERAL.Id;
3364 SELECT COUNT(Computer) FROM CONNEXION, COMPUTER WHERE Model = 'Apple IIc Plus' AND Computer = COMPUTER.Id;
3365 ~~~
3366
3367 ---
3368
3369 3419 Solution to [%D %n (%T)](#problem:address) Solution to [%D %n (%T)](#problem:address)
3370 3420 ~ ~
3371 3421
 
... ... Solution to [%D %n (%T)](#problem:coffee)
3663 3713
3664 3714 --- ---
3665 3715
3716 Solution to [%D %n (%T)](#problem:ComputerSelectBis)
3717
3718 ~
3719
3720 ~~~{.sqlmysql}
3721 SELECT Model FROM COMPUTER WHERE Id = 'A';
3722 SELECT Type FROM PERIPHERAL WHERE Id = '14';
3723 SELECT Model FROM PERIPHERAL WHERE Type = 'printer';
3724 SELECT Model FROM PERIPHERAL WHERE Model LIKE 'IBM%';
3725 SELECT Model FROM PERIPHERAL, CONNEXION WHERE Computer = 'A' AND Peripheral = PERIPHERAL.Id;
3726 SELECT COUNT(Computer) FROM CONNEXION, COMPUTER WHERE Model = 'Apple IIc Plus' AND Computer = COMPUTER.Id;
3727 ~~~
3728
3729 ---
3730
3666 3731 Solution to [%D %n (%T)](#problem:roleplaying) Solution to [%D %n (%T)](#problem:roleplaying)
3667 3732 ~ ~
3668 3733
File notes/temp.md changed (mode: 100644) (index 14e49c8..0520448)
... ... pandoc-numbering:
29 29 format-link-title: 'Pb %n' format-link-title: 'Pb %n'
30 30 --- ---
31 31
32 ${A}$
33 $\{A\}$
34 [Test](http://train.test)
32 ```{.sqlmysql .numberLines include=code/sql/HW_DB_COFFEE.sql}
33 ```
35 34
36 35 <!-- <!--
37 36
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