List of commits:
Subject Hash Author Date (UTC)
Added simple examples for SQL. 4ea62f6930ff19bcff8d406d95c9cd84c0f0216d caubert 2021-02-02 22:24:41
Added first project. e851058cc58a9d47ada9970f8b914e798c7d2ce7 caubert 2021-01-27 19:57:12
Few typos. 45ba15cd03fab4388439b617c656f52b2ec96319 caubert 2021-01-26 20:08:24
Small fix in code. 7860e391d0bbe82336b8f05585f846e829d181b1 caubert 2021-01-26 18:55:17
Fixed various bugs. fa76c1e469a4263d7bb7da79532abd1eedcc49be caubert 2021-01-22 19:27:01
First quizz, and fix bug with code displayed. bc9b6bb097e30186805b02dc1cdc5de2d5feabe4 caubert 2021-01-22 19:21:54
Edited the preamble. 364e709107602e163ea9365f25ccf1f5a6bb1914 caubert 2021-01-11 16:00:07
Started to edit notes and add final exam from fall 2020. bb747e27ce08ce17e91913e947614e3057580995 caubert 2021-01-06 22:26:07
Integrated the include-link feature of pandoc-include-code. 3a8f9ededdaa1f05d526742f5d447aaa017e1d1b caubert 2021-01-04 22:52:18
Fixed citeproc. 0d90c7e60e4a4474fd7ded03bb6526ea63a57253 aubert@math.cnrs.fr 2020-12-27 21:33:48
(Finally) updated pandoc and pandoc-numbering. 127c1964a0732b49e14b46fdb0d3f8446e3892d0 aubert@math.cnrs.fr 2020-12-27 21:14:31
Fixed url in comments, avoid them being wrapped. 09a6a78479f24b5749605a4cb7136f8cfbf57d30 aubert@math.cnrs.fr 2020-12-18 18:55:50
Added comments on procedures from code f3e9c2abac41d5de1c7473867c4f688051dec928 aubert@math.cnrs.fr 2020-12-01 15:46:53
Updated mysql connector 228d86db5498aae94a4d162272fa03a84ae9c532 aubert@math.cnrs.fr 2020-12-01 15:09:46
Updated java beautifier 30f4a79f2d911cd0b6a24c31f968f0d23620965f aubert@math.cnrs.fr 2020-12-01 15:07:50
Worked on procedure example from java 998ea14119a5a3f88efc4b0a126177e85151e43d aubert@math.cnrs.fr 2020-12-01 15:06:47
Brief example of calling a procedure from a program. 1054c9d5c83fb956bdd0b8d884d5ce2c8a9a640e aubert@math.cnrs.fr 2020-11-30 19:00:45
Added solution to second exam d8f62ded96991885a96d561db587988d453a28c8 aubert@math.cnrs.fr 2020-11-05 20:35:50
Quick fix on testing semicolons. 7f48d88d2ed69213d803a7736df3d50330cfecd1 aubert@math.cnrs.fr 2020-11-03 14:14:06
Added simple example to test if semicolon are important in SQL querries. 98097fb11558c08bad630fb3351f99ceb6777de7 aubert@math.cnrs.fr 2020-11-03 14:11:22
Commit 4ea62f6930ff19bcff8d406d95c9cd84c0f0216d - Added simple examples for SQL.
Author: caubert
Author date (UTC): 2021-02-02 22:24
Committer name: caubert
Committer date (UTC): 2021-02-02 22:24
Parent(s): e851058cc58a9d47ada9970f8b914e798c7d2ce7
Signer:
Signing key:
Signing status: N
Tree: c610579e1a05adf792650ff7e47d9c62be702de3
File Lines added Lines deleted
notes/code/sql/HW_AutoIncrement.sql 17 0
notes/code/sql/HW_DefaultTest.sql 36 3
notes/lectures_notes.md 51 9
File notes/code/sql/HW_AutoIncrement.sql added (mode: 100644) (index 0000000..c02e7ad)
1 DROP SCHEMA IF EXISTS HW_AutoIncrement;
2 CREATE SCHEMA HW_AutoIncrement;
3 USE HW_AutoIncrement;
4
5 -- start snippet demo1
6 /* code/sql/HW_AutoIncrement.sql */
7 CREATE TABLE PERSON (
8 PersonID INT AUTO_INCREMENT,
9 Name VARCHAR(255),
10 PRIMARY KEY (PersonID)
11 );
12
13 INSERT INTO PERSON (Name)
14 VALUES ('Lars'), ('Kristina'), ('Sophie');
15
16 SELECT * FROM PERSON;
17 -- end snippet demo1
File notes/code/sql/HW_DefaultTest.sql changed (mode: 100644) (index 825f91e..2f92d0b)
1 /* code/sql/HW_DefaultTest.sql */
2 1 DROP SCHEMA IF EXISTS HW_DEFAULT_test; DROP SCHEMA IF EXISTS HW_DEFAULT_test;
3
4 2 CREATE SCHEMA HW_DEFAULT_test; CREATE SCHEMA HW_DEFAULT_test;
5
6 3 USE HW_DEFAULT_test; USE HW_DEFAULT_test;
7 4
5 -- start snippet demo1
6 /* code/sql/HW_DefaultTest.sql */
7
8 8 CREATE TABLE TEST ( CREATE TABLE TEST (
9 9 TestA VARCHAR(15), TestA VARCHAR(15),
10 10 TestB INT, TestB INT,
 
... ... VALUES (
25 25
26 26 SELECT * SELECT *
27 27 FROM TEST; FROM TEST;
28 -- end snippet demo1
29
30 -- start snippet modif1
31 /* code/sql/HW_DefaultTest.sql */
32 ALTER TABLE TEST ALTER COLUMN TestA SET DEFAULT "A";
33
34 SELECT *
35 FROM TEST;
36 --end snippet modif1
37
38 -- start snippet modif2
39 /* code/sql/HW_DefaultTest.sql */
40 INSERT INTO TEST (TestB)
41 VALUES (1);
42
43 SELECT *
44 FROM TEST;
45 -- The value of TestA is set to "A",
46 -- all the other values are set to NULL.
47 -- end snippet modif2
48
49 -- start snippet demo2
50 /* code/sql/HW_DefaultTest.sql */
51 SELECT * FROM TEST WHERE TestA = "A";
52 SELECT * FROM TEST WHERE TestA <> "A";
53 -- end snippet demo2
54
55
56 -- start snippet demo3
57 /* code/sql/HW_DefaultTest.sql */
58 SELECT * FROM TEST WHERE TestA IS NULL;
59 SELECT * FROM TEST WHERE TestA IS NOT NULL;
60 -- end snippet demo3
File notes/lectures_notes.md changed (mode: 100644) (index aa72ea4..979bd9e)
... ... To use the `DEFAULT` value, use
1734 1734 INSERT INTO HURRICANE VALUES ("Test2", DEFAULT, NULL); INSERT INTO HURRICANE VALUES ("Test2", DEFAULT, NULL);
1735 1735 ``` ```
1736 1736
1737 Note that, by default, the `DEFAULT` value is `NULL`, regardless of the datatype:
1737 Note that, by default, the `DEFAULT` value is `NULL`, regardless of the datatype.
1738 You can experiment it by running the following code:
1738 1739
1739 1740
1740 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql}
1741 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=demo1}
1741 1742 ``` ```
1742 1743
1743 1744 ### Editing Constraints ### Editing Constraints
 
... ... Removing the default value:
1807 1808 ALTER TABLE HURRICANE ALTER COLUMN WindSpeed DROP DEFAULT; ALTER TABLE HURRICANE ALTER COLUMN WindSpeed DROP DEFAULT;
1808 1809 ``` ```
1809 1810
1811 Note that if you change the default value, it does *not* change the values you inserted retro-actively.
1812 To resume on our previous example, the values inserted with `DEFAULT` as a value would still be `NULL` even after executing the following instruction:
1813
1814 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=modif1}
1815 ```
1816
1810 1817 #### Foreign key #### Foreign key
1811 1818
1812 1819 Adding a foreign key constraint: Adding a foreign key constraint:
 
... ... And we can even specify the order (even the trivial one):
2083 2090 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_ProfExample.sql snippet=insert-3} ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_ProfExample.sql snippet=insert-3}
2084 2091 ``` ```
2085 2092
2086 Note the date literals.
2093 (Note the date literals)
2094
2095 By default, the values that are not given are set to their respective `DEFAULT` values.
2096
2097 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=modif2}
2098 ```
2087 2099
2088 2100 ### A Bit More on Foreign Keys ### A Bit More on Foreign Keys
2089 2101
 
... ... The `COLLATE` operator can be used to force the search to be case-sensitive, as
2147 2159
2148 2160 Cf. [@Textbook6, 5.1.1], [@Textbook7, 7.1.1] Cf. [@Textbook6, 5.1.1], [@Textbook7, 7.1.1]
2149 2161
2162 The Boolean logic in SQL is three-valued: a statement can be `true`, `false` or `unknown`.
2163 If you pick the following two commands:
2164
2165
2166 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=demo2}
2167 ```
2168
2169 you may believe that they will capture all the tuples in the `TEST` table, as the value for `TestA` is either `"A"` or not `"A"`, but you would be wrong.
2170 If the value of `TestA` is `NULL`, then both conditions would fail, as SQL cannot say that the value is or is not `"A"`: it is simply undefined!
2171
2172
2150 2173 ### Meaning of `NULL` ### Meaning of `NULL`
2151 2174
2152 2175 `NULL` is `NULL` is
2153 2176
2154 #. Unknown value ("Nobody knows")
2177 #. Unknown value ("_Nobody knows_")
2155 2178
2156 2179 > What is the date of birth of [Jack the Ripper](https://en.wikipedia.org/wiki/Jack_the_Ripper)? > What is the date of birth of [Jack the Ripper](https://en.wikipedia.org/wiki/Jack_the_Ripper)?
2157 2180
2158 2181 > [Does P equal NP?](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_computer_science) > [Does P equal NP?](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_computer_science)
2159 2182
2160 #. Unavailable / Withheld ("I do not have that information with me at the moment")
2183 #. Unavailable / Withheld ("_I do not have that information with me at the moment_")
2161 2184
2162 2185 > What is the number of english spies in France? > What is the number of english spies in France?
2163 2186
 
... ... Cf. [@Textbook6, 5.1.1], [@Textbook7, 7.1.1]
2165 2188
2166 2189 > What is the identity of the Tiananmen Square person? > What is the identity of the Tiananmen Square person?
2167 2190
2168 #. Not Applicable ("Your question does not make sense")
2191 #. Not Applicable ("_Your question does not make sense_")
2169 2192
2170 > What is the US SSN of a french person?
2193 > What is the US SSN of a French person?
2171 2194
2172 > What is the email address of an author of the XIXth century?
2195 > What is the email address of an author of the XIX^th^ century?
2173 2196
2174 2197 ### Comparison with Unknown Values {#truth-tables} ### Comparison with Unknown Values {#truth-tables}
2175 2198
2176 2199 If `NULL` is involved in a comparison, the result evaluates to "**U**nknown." If `NULL` is involved in a comparison, the result evaluates to "**U**nknown."
2177 If `NULL` is involved in a comparison, the result evaluates to "**U**nknown".
2178 2200
2179 2201 |||| ||||
2180 2202 :--: | :--: | :--: | :--: :--: | :--: | :--: | :--:
 
... ... You can test if a value is `NULL` with `IS NULL`.
2205 2227
2206 2228 Note that you can not use `IS` to compare values: this key word is reserved to test if a value is (not) `NULL`, and nothing else. Note that you can not use `IS` to compare values: this key word is reserved to test if a value is (not) `NULL`, and nothing else.
2207 2229
2230 This means that if you want to capture all the tuples, you cannot write
2231
2232 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=demo2}
2233 ```
2234
2235 but should have something like
2236
2237 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_DefaultTest.sql snippet=demo3}
2238 ```
2239
2240 ### Trivia
2241
2208 2242 There are no `if…then…else` statements in `SQL`, but you can do something similar with `CASE` (cf. <https://dev.mysql.com/doc/refman/8.0/en/case.html>). There are no `if…then…else` statements in `SQL`, but you can do something similar with `CASE` (cf. <https://dev.mysql.com/doc/refman/8.0/en/case.html>).
2209 2243 However, note that `SQL` is probably _not_ the right place to try to control the flow of execution. However, note that `SQL` is probably _not_ the right place to try to control the flow of execution.
2210 2244
 
... ... For aggregate functions, cf. [@Textbook6, 5.1.7] or [@Textbook7, 7.1.7].
2223 2257 Something that is not exactly a constraint, but that can be used to "qualify" domains, is the `AUTO_INCREMENT` feature of MySQL. Something that is not exactly a constraint, but that can be used to "qualify" domains, is the `AUTO_INCREMENT` feature of MySQL.
2224 2258 Cf. <https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html>, you can have MySQL increment a particular attribute (most probably intended to be your primary key, or some form of counter) for you. Cf. <https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html>, you can have MySQL increment a particular attribute (most probably intended to be your primary key, or some form of counter) for you.
2225 2259
2260 A typical example could be:
2261
2262 ```{.sqlmysql .numberLines .includeLink include=code/sql/HW_AutoIncrement.sql snippet=demo1}
2263 ```
2264
2265 This way, the burden of having to keep track of the persons' ids is left to the program, and not to the person inserting data in the table.
2266
2267
2226 2268 ### Transactions ### Transactions
2227 2269
2228 2270 We can save the current state, and start a series of transactions, with the command We can save the current state, and start a series of transactions, with the 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