List of commits:
Subject Hash Author Date (UTC)
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
Added activity diagram. 11c9acfa88c398f7463d6e54f45ea48c8793caf1 aubert@math.cnrs.fr 2020-05-15 14:34:31
Added activity diagram. 995cf4f64c43601716f77bb46d1535025ea14d10 aubert@math.cnrs.fr 2020-05-15 14:33:30
Edits in intro, converted an image to a figure for example of class diagram. 1ff4ef2f7f44ece81972a6c77e9f6654c144fcdc aubert@math.cnrs.fr 2020-05-14 22:12:38
Adding example file, to test installation. 5ed35e64a4e4dc60c888358bde54594999aab34d aubert@math.cnrs.fr 2020-05-13 19:03:41
Commit 5bdb4faed3a83b81257734f1e1aced2890783f04 - Cleaned code.
Author: aubert@math.cnrs.fr
Author date (UTC): 2020-09-03 21:35
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2020-09-03 21:35
Parent(s): 564a02887933f2395bc40d7d8a10833f657659fd
Signer:
Signing key:
Signing status: N
Tree: 74f03bd37e33495a8664efcaab4850a07953e2bc
File Lines added Lines deleted
notes/code/sql/HW_AdvancedFK.sql 32 0
notes/code/sql/HW_Captone.sql 88 125
notes/code/sql/HW_Certificate.sql 20 19
notes/code/sql/HW_ConstraintsPart1.sql 1 1
notes/code/sql/HW_DBCoffee.sql 9 9
notes/code/sql/HW_Department.sql 1 1
notes/code/sql/HW_Faculty.sql 1 1
notes/code/sql/HW_ProcedureExamples.sql 3 3
notes/code/sql/HW_ProfExample.sql 2 2
notes/code/sql/HW_ResidencySol.sql 21 21
notes/code/sql/HW_SocialMedia.sql 9 9
notes/code/sql/HW_Storm.sql 18 17
notes/code/sql/HW_TriggerExample.sql 10 10
notes/code/sql/HW_Work.sql 24 24
notes/lectures_notes.md 7 0
File notes/code/sql/HW_AdvancedFK.sql added (mode: 100644) (index 0000000..733c028)
1 DROP SCHEMA IF EXISTS HW_AdvancedFK;
2
3 CREATE SCHEMA HW_AdvancedFK;
4
5 USE HW_AdvancedFK;
6
7 -- start snippet advancedFK
8 /* code/sql/HW_AdvancedFK.sql */
9 CREATE TABLE T1 (
10 A1 INT, A2 INT, B INT, PRIMARY KEY (A1, A2)
11 );
12
13 CREATE TABLE T2 (
14 A1 INT, A2 INT, B1 INT PRIMARY KEY, B2 INT,
15 -- We can create a "pair" of foreign key in one line, as
16 -- follows:
17 FOREIGN KEY (A1, A2) REFERENCES T1 (A1, A2),
18 -- We can create a foreign key that references the primary
19 -- key of the table we are currently creating, and name it,
20 -- as follows:
21 CONSTRAINT My_pk_to_T1 FOREIGN KEY (B2) REFERENCES T2 (B1)
22 );
23
24 -- The benefit of naming our fk constraint is that, if we
25 -- violate it, for instance with
26 -- INSERT INTO T2 VALUES (1, 1, 1, 3);
27 -- then the name of the constraint (here "My_pk_to_T1")
28 -- would be displayed in the error message:
29 -- Cannot add or update a child row: a foreign key
30 -- constraint fails (`db_9_9837c1`.`t2`, CONSTRAINT
31 -- `My_pk_to_T1` FOREIGN KEY (`B2`) REFERENCES `t2` (`B1`))
32 -- end snippet advancedFK
File notes/code/sql/HW_Captone.sql changed (mode: 100644) (index 87cd119..717e745)
1 1 /* code/sql/HW_CaptoneSol.sql */ /* code/sql/HW_CaptoneSol.sql */
2
3
4 2 /* /*
5 3 * *
6 4 * Look for "FILL HERE" * Look for "FILL HERE"
7 5 * *
8 6 */ */
9
10 7 -- NAME -- FILL HERE -- NAME -- FILL HERE
11 8 -- DATE -- FILL HERE -- DATE -- FILL HERE
12 9 -- CSCI 3410 - Project 1 -- CSCI 3410 - Project 1
13
14 10 /* /*
15 11 * *
16 12 * DO **NOT** EDIT THE CODE BELOW * DO **NOT** EDIT THE CODE BELOW
17 13 * *
18 14 */ */
19
20 15 DROP SCHEMA IF EXISTS HW_CAPSTONE; DROP SCHEMA IF EXISTS HW_CAPSTONE;
21 16
22 17 CREATE SCHEMA HW_CAPSTONE; CREATE SCHEMA HW_CAPSTONE;
 
... ... CREATE SCHEMA HW_CAPSTONE;
24 19 USE HW_CAPSTONE; USE HW_CAPSTONE;
25 20
26 21 CREATE TABLE STUDENT ( CREATE TABLE STUDENT (
27 FName VARCHAR(50),
28 Id CHAR(13) PRIMARY KEY,
29 GraduationYear INT,
30 GraduationSemester ENUM ("Fall", "Spring", "Summer")
22 FName VARCHAR(50), Id CHAR(13) PRIMARY KEY,
23 GraduationYear INT, GraduationSemester ENUM ("Fall",
24 "Spring", "Summer")
31 25 ); );
32 26
33 CREATE TABLE PROGRAMMING_LANGUAGE(
34 Name VARCHAR(50) PRIMARY KEY,
35 Licence VARCHAR(50)
36 );
27 CREATE TABLE PROGRAMMING_LANGUAGE (
28 NAME VARCHAR(50) PRIMARY KEY, Licence VARCHAR(50)
29 );
37 30
38 31 CREATE TABLE PROJECT ( CREATE TABLE PROJECT (
39 CodeName VARCHAR(50),
40 Leader CHAR(13),
41 PRIMARY KEY (CodeName, Leader),
42 FOREIGN KEY (Leader) REFERENCES STUDENT(Id)
32 CodeName VARCHAR(50), Leader CHAR(13), PRIMARY KEY
33 (CodeName, Leader),
34 FOREIGN KEY (Leader) REFERENCES STUDENT (Id)
43 35 ); );
44 36
45 CREATE TABLE USED_LANGUAGE(
46 ProjectCodeName VARCHAR(50),
47 ProjectLeader CHAR(13),
48 UsedLanguage VARCHAR(50),
49 PRIMARY KEY (ProjectCodeName, ProjectLeader, UsedLanguage),
50 FOREIGN KEY (ProjectCodeName) REFERENCES PROJECT(CodeName),
51 FOREIGN KEY (ProjectLeader) REFERENCES PROJECT(Leader),
52 FOREIGN KEY (UsedLanguage) REFERENCES PROGRAMMING_LANGUAGE(Name)
37 CREATE TABLE USED_LANGUAGE (
38 ProjectCodeName VARCHAR(50), ProjectLeader CHAR(13),
39 UsedLanguage VARCHAR(50), PRIMARY KEY (ProjectCodeName,
40 ProjectLeader, UsedLanguage), FOREIGN KEY
41 (ProjectCodeName) REFERENCES PROJECT (CodeName),
42 FOREIGN KEY (ProjectLeader) REFERENCES PROJECT
43 (Leader),
44 FOREIGN KEY (UsedLanguage) REFERENCES PROGRAMMING_LANGUAGE (NAME)
53 45 ); );
54 46
47
55 48 /* /*
56 49 The meaning of the USED_LANGUAGE table is that a tuple  < N, L, U> represents the fact that the project whose code name is N and whose leader is L uses the programming language U. The meaning of the USED_LANGUAGE table is that a tuple  < N, L, U> represents the fact that the project whose code name is N and whose leader is L uses the programming language U.
57 50 */ */
58
59
60 51 INSERT INTO STUDENT INSERT INTO STUDENT
61 VALUES
62 ("Mary", "0123456789100", 2025, "Summer"),
63 ("Steve", "0000000000000", 2025, "Fall" ),
64 ("Claude", "9999999999999", 2024, "Fall" ),
65 ("Meghan", "0987654321098", 2023, "Spring");
52 VALUES ("Mary", "0123456789100", 2025, "Summer"),
53 ("Steve", "0000000000000", 2025, "Fall"), ("Claude",
54 "9999999999999", 2024, "Fall"), ("Meghan",
55 "0987654321098", 2023, "Spring");
66 56
67 57 INSERT INTO PROGRAMMING_LANGUAGE INSERT INTO PROGRAMMING_LANGUAGE
68 VALUES
69 ("Rust", "MIT" ),
70 (".NET Core", "MIT" ),
71 ("Racket", "LGPL"),
72 ("Python", "PSF" );
73 -- Taken from https://en.wikipedia.org/wiki/Comparison_of_open-source_programming_language_licensing
74
75 INSERT INTO PROJECT
76 VALUES
77 ("Brick Break", "0123456789100"),
78 ("Brick Break", "0000000000000"),
79 ("Grade Calculator", "0123456789100"),
80 ("Undecided", "9999999999999")
81 ;
82
83 INSERT INTO USED_LANGUAGE
84 VALUES
85 ("Brick Break", "0123456789100", "Rust" ),
86 ("Brick Break", "0000000000000", ".NET Core"),
87 ("Brick Break", "0000000000000", "Python" ),
88 ("Grade Calculator", "0123456789100", "Racket" )
89 ;
58 VALUES ("Rust", "MIT"), (".NET Core", "MIT"), ("Racket",
59 "LGPL"), ("Python", "PSF");
60
61 -- Taken from
62 -- https://en.wikipedia.org/wiki/Comparison_of_open-source_pr
63 -- ogramming_language_licensing
64 INSERT INTO PROJECT
65 VALUES ("Brick Break", "0123456789100"), ("Brick Break",
66 "0000000000000"), ("Grade Calculator",
67 "0123456789100"), ("Undecided", "9999999999999");
68
69 INSERT INTO USED_LANGUAGE
70 VALUES ("Brick Break", "0123456789100", "Rust"), ("Brick
71 Break", "0000000000000", ".NET Core"), ("Brick Break",
72 "0000000000000", "Python"), ("Grade Calculator",
73 "0123456789100", "Racket");
74
90 75
91 76 /* /*
92 77 * You can start editing starting here. * You can start editing starting here.
93 78 */ */
94
95 79 /* /*
96 80
97 81 I. Short Questions (6 pts) I. Short Questions (6 pts)
98 82
99 83 Answer the following short questions based on the model implemented above. Answer the following short questions based on the model implemented above.
100 84 You can simply answer "True" or "False", or justify your reasoning (e.g. with code). You can simply answer "True" or "False", or justify your reasoning (e.g. with code).
101
102 */
103
85 */
104 86 -- 1. Can a project uses multiple programming languages? -- 1. Can a project uses multiple programming languages?
105
106
107
108
109
110
111
112
113
114
115
116
117
87 -- FILL HERE
88 -- 2. Can a student be the leader of multiple projects?
89 -- FILL HERE
90 -- 3. Can multiple projects have the same code name?
91 -- FILL HERE
92 -- 4. Could Claude simply enter NULL for the value of his
93 -- project's code name, since he's undecided?
94 -- FILL HERE
95 -- 5. Can a project be created without project leader?
96 -- FILL HERE
97 -- 6. Can we know who is working on a project without being
98 -- its leader?
99 -- FILL HERE
118 100 /* /*
119 101
120 102 II. Relational Model (6 pts.) II. Relational Model (6 pts.)
121 103
122 104 Draw the relational model corresponding to this code. Draw the relational model corresponding to this code.
123 105 You can hand-draw it and join a scan or a picture, or simply hand me back the sheet where you drew it. You can hand-draw it and join a scan or a picture, or simply hand me back the sheet where you drew it.
124
125 */
126
127
106 */
128 107 /* /*
129 108
130 109 III. Simple Commands (8 pts.) III. Simple Commands (8 pts.)
 
... ... III. Simple Commands (8 pts.)
143 111 Below, you are asked to write commands that perform various actions. Below, you are asked to write commands that perform various actions.
144 112 Please, leave them uncommented, unless you can't write them correctly, in which case it's ok to leave them commented. Please, leave them uncommented, unless you can't write them correctly, in which case it's ok to leave them commented.
145 113 The first question is answered as an example. The first question is answered as an example.
146
147 */
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
114 */
115 -- 0. Write a command that list all the names of the
116 -- programming languages.
117 -- FILL HERE
118 -- 1. Write a command that insert a new student in the
119 -- STUDENT table.
120 -- (You should invent the values).
121 -- FILL HERE
122 -- 2. Write a command that updates the code name of the
123 -- project ("Undecided", "9999999999999") to "VR in ER".
124 -- FILL HERE
125 -- 3. Write a command that updates the graduation year of
126 -- the student whose id is "0987654321098" to 2024, and the
127 -- semester to "Fall".
128 -- FILL HERE
129 -- 4. Write a command that changes the STUDENT table to make
130 -- it impossible to enter NULL for the first name of a
131 -- student, without changing the primary key.
132 -- FILL HERE
133 -- 5. Write a command that changes the datatype of
134 -- GraduationYear to SMALLINT.
135 -- FILL HERE
136 -- 6. Write a command that adds an attribute "ReleaseDate"
137 -- to the PROJECT table.
138 -- FILL HERE
139 -- 6.bis If you managed to write the previous command
140 -- correctly, write a command that sets the release date of
141 -- the project ("Brick Break", "0123456789100") to the 26th
142 -- of November 2022.
143 -- FILL HERE
144 -- 7. Write a command that makes it impossible for a student
145 -- to be the leader in more than one project
146 -- (This command should return an error)
147 -- FILL HERE
File notes/code/sql/HW_Certificate.sql changed (mode: 100644) (index a11be3d..166369b)
... ... SELECT CN
47 47 FROM CERTIFICATE; FROM CERTIFICATE;
48 48
49 49 -- (*.wikimedia.org | *.fsf.org | *.shadytest.org | -- (*.wikimedia.org | *.fsf.org | *.shadytest.org |
50 -- *.wikipedia.org)
51 -- The SN of the organizations whose CN contains
52 -- "Foundation"
50 53 SELECT SN SELECT SN
51 54 FROM ORGANIZATION FROM ORGANIZATION
52 55 WHERE CN LIKE "%Foundation%"; WHERE CN LIKE "%Foundation%";
53 56
54 57 -- (01 | 02) -- (01 | 02)
58 -- The CN and expiration date of all the certificates
59 -- that
60 -- expired (assuming we are the 6th of December 2019).
55 61 SELECT CN, Valid_Until SELECT CN, Valid_Until
56 62 FROM CERTIFICATE FROM CERTIFICATE
57 63 WHERE Valid_Until < DATE '20191206'; WHERE Valid_Until < DATE '20191206';
58 64
59 65 -- (*.fsf.org, 2019-10-10) -- (*.fsf.org, 2019-10-10)
66 -- The CN of the CA that are not trusted.
60 67 SELECT CN SELECT CN
61 68 FROM CA FROM CA
62 69 WHERE Trusted IS NOT TRUE; WHERE Trusted IS NOT TRUE;
63 70
64 71 -- (Shady Corp. | NewComer Ltd.) -- (Shady Corp. | NewComer Ltd.)
72 -- The CN of the certificates that are signed by a CA
73 -- that
74 -- is not trusted.
65 75 SELECT CERTIFICATE.CN SELECT CERTIFICATE.CN
66 76 FROM CERTIFICATE, CA FROM CERTIFICATE, CA
67 77 WHERE Trusted IS NOT TRUE WHERE Trusted IS NOT TRUE
68 78 AND CA.SN = CERTIFICATE.Issuer; AND CA.SN = CERTIFICATE.Issuer;
69 79
70 80 -- (Shady Corp. | NewComer Ltd.) -- (Shady Corp. | NewComer Ltd.)
81 -- The number of certificates signed by the CA whose CN
82 -- is
83 -- "Let's encrypt".
71 84 SELECT COUNT(CERTIFICATE.SN) AS "Number of certificates signed SELECT COUNT(CERTIFICATE.SN) AS "Number of certificates signed
72 85 by Let's encrypt" by Let's encrypt"
73 86 FROM CERTIFICATE, CA FROM CERTIFICATE, CA
 
... ... WHERE CERTIFICATE.Issuer = CA.SN
88 88 AND CA.CN = "Let's encrypt"; AND CA.CN = "Let's encrypt";
89 89
90 90 -- (2) -- (2)
91 -- A table listing the CN of the organizations along
92 -- with
93 -- the CN of their certificates.
91 94 SELECT ORGANIZATION.CN AS Organization, CERTIFICATE.CN AS SELECT ORGANIZATION.CN AS Organization, CERTIFICATE.CN AS
92 95 Certificate Certificate
93 96 FROM ORGANIZATION, CERTIFICATE FROM ORGANIZATION, CERTIFICATE
94 97 WHERE CERTIFICATE.Org = ORGANIZATION.SN; WHERE CERTIFICATE.Org = ORGANIZATION.SN;
95 98
96 99 -- ( Wikimedia Foundation, *.wikimedia.org | Free Software -- ( Wikimedia Foundation, *.wikimedia.org | Free Software
100 -- Foundation, *.fsf.org | Free Software Foundation ,
101 -- *.shadytest.org | Wikimedia Foundation ,
102 -- *.wikipedia.org
103 -- )
97 104 /* /*
98 105 DELETE FROM CA WHERE SN = 'A'; DELETE FROM CA WHERE SN = 'A';
99 106 ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`HW_Certificate`.`CERTIFICATE`, CONSTRAINT `CERTIFICATE_ibfk_2` FOREIGN KEY (`Issuer`) REFERENCES `CA` (`SN`)) ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`HW_Certificate`.`CERTIFICATE`, CONSTRAINT `CERTIFICATE_ibfk_2` FOREIGN KEY (`Issuer`) REFERENCES `CA` (`SN`))
File notes/code/sql/HW_ConstraintsPart1.sql changed (mode: 100644) (index c8a2dff..22dcc46)
... ... CREATE TABLE HURRICANE (
9 9 NAME VARCHAR(25) PRIMARY KEY, WindSpeed INT DEFAULT 76 NAME VARCHAR(25) PRIMARY KEY, WindSpeed INT DEFAULT 76
10 10 CHECK (WindSpeed > 74 AND WindSpeed < 500), CHECK (WindSpeed > 74 AND WindSpeed < 500),
11 11 -- 75mph is the minimum to be considered as a hurricane -- 75mph is the minimum to be considered as a hurricane
12 -- cf. https://www.hwn.org/resources/bws.html
12 -- cf. https://www.hwn.org/resources/bws.html
13 13 Above VARCHAR(25) Above VARCHAR(25)
14 14 ); );
15 15
File notes/code/sql/HW_DBCoffee.sql changed (mode: 100644) (index 35c177b..0165d95)
... ... INSERT INTO COFFEE
61 61 VALUES (002, "Peru", "Decaf", 3.00); VALUES (002, "Peru", "Decaf", 3.00);
62 62
63 63 -- The following statement raises an error. -- The following statement raises an error.
64 -- INSERT INTO PROVIDER
65 -- VALUES (NULL, "contact@localcof.com");
66 -- ERROR 1048 (23000) at line 68: Column 'Name' cannot be
67 -- null
64 68 INSERT INTO SUPPLY INSERT INTO SUPPLY
65 69 VALUES ("Johns & Co.", 121); VALUES ("Johns & Co.", 121);
66 70
67 71 -- The following statement raises an error. -- The following statement raises an error.
72 -- -INSERT INTO SUPPLY
73 -- VALUES ("Coffee Unl.", 311, 221);
74 -- ERROR 1136 (21S01): Column count doesn't match value
75 -- count at row 1
76 -- Rest the changes:
68 77 ROLLBACK; ROLLBACK;
69 78
70 79 -- Question 3: -- Question 3:
File notes/code/sql/HW_Department.sql changed (mode: 100644) (index aa23331..9956d14)
5 5 DROP SCHEMA IF EXISTS HW_Department; DROP SCHEMA IF EXISTS HW_Department;
6 6
7 7 -- Carefull, we are dropping the schema HW_Department if it -- Carefull, we are dropping the schema HW_Department if it
8 -- exists already, and all the data in it.
8 9 CREATE SCHEMA HW_Department; CREATE SCHEMA HW_Department;
9 10
10 11 -- And then re-creating it. -- And then re-creating it.
File notes/code/sql/HW_Faculty.sql changed (mode: 100644) (index 1d6be25..631b969)
... ... INSERT INTO PROF
62 62 290, 'PhD', 0, NULL, '19940101', -- Or '940101', '1994-01-01', '94/01/01' 290, 'PhD', 0, NULL, '19940101', -- Or '940101', '1994-01-01', '94/01/01'
63 63 '090500', -- Or '09:05:00', '9:05:0', '9:5:0', '090500' '090500', -- Or '09:05:00', '9:05:0', '9:5:0', '090500'
64 64 -- Note also the existence of DATETIME, with 'YYYY-MM-DD -- Note also the existence of DATETIME, with 'YYYY-MM-DD
65 -- HH:MM:SS'
65 -- HH:MM:SS'
66 66 'Apple' -- This is not case-sensitive, oddly enough. 'Apple' -- This is not case-sensitive, oddly enough.
67 67 ); );
File notes/code/sql/HW_ProcedureExamples.sql changed (mode: 100644) (index 5ee7e4d..675bb21)
... ... BEGIN
27 27 END; END;
28 28 $$ $$
29 29 -- This is the delimiter that marks the end of the procedure -- This is the delimiter that marks the end of the procedure
30 -- definition.
30 31 DELIMITER ; DELIMITER ;
31 32
32 33 -- Now, we want ";" to be the "natural" delimiter again. -- Now, we want ";" to be the "natural" delimiter again.
 
... ... DELIMITER ;
54 54 SHOW CREATE PROCEDURE STUDENTLOGIN; SHOW CREATE PROCEDURE STUDENTLOGIN;
55 55
56 56 -- This display information about the procedure just created. -- This display information about the procedure just created.
57 -- We can pass quite naturally an argument to our
58 -- procedure.
57 59 CALL STUDENTLOGIN ("Test A"); CALL STUDENTLOGIN ("Test A");
58 60
59 61 -- end snippet procedure-3 -- end snippet procedure-3
File notes/code/sql/HW_ProfExample.sql changed (mode: 100644) (index 34d394d..2e070cc)
... ... WHERE DEPARTMENT.Name = "Mathematics"
142 142 AND Department = Code; AND Department = Code;
143 143
144 144 -- end snippet select-project-join-1 -- end snippet select-project-join-1
145 -- start snippet select-project-join-2
145 146 SELECT Name SELECT Name
146 147 FROM STUDENT, GRADE FROM STUDENT, GRADE
147 148 WHERE Grade > 3.0 WHERE Grade > 3.0
148 149 AND STUDENT.Login = GRADE.Login; AND STUDENT.Login = GRADE.Login;
149 150
150 151 -- end snippet select-project-join-2 -- end snippet select-project-join-2
152 -- start snippet select-project-join-3
151 153 SELECT PROF.Name SELECT PROF.Name
152 154 FROM PROF, DEPARTMENT, STUDENT FROM PROF, DEPARTMENT, STUDENT
153 155 WHERE STUDENT.Name = "Ava Alyx" WHERE STUDENT.Name = "Ava Alyx"
File notes/code/sql/HW_ResidencySol.sql changed (mode: 100644) (index 29ba036..32b09f4)
... ... INSERT INTO RESIDENCY
54 54 the next question. the next question.
55 55 */ */
56 56 -- Exercise 4 -- Exercise 4
57 -- List the rows (i.e., P.2, H.1, or even “none”)
58 -- modified by the following statements:
57 59 START TRANSACTION; START TRANSACTION;
58 60
59 61 UPDATE UPDATE
 
... ... ROLLBACK;
84 84 START TRANSACTION; START TRANSACTION;
85 85
86 86 -- Commented, because it causes an error. -- Commented, because it causes an error.
87 -- DELETE FROM PERSON
88 -- WHERE Birthdate = DATE "1990-02-11";
89 -- None, because of the foreign key and the referential
90 -- integrity constraint.
91 -- ERROR 1451 (23000): Cannot delete or update a parent
92 -- row:
93 -- a foreign key constraint fails
94 -- (`HW_RESIDENCY_SOL`.`RESIDENCY`, CONSTRAINT
95 -- `RESIDENCY_ibfk_1` FOREIGN KEY (`Person`) REFERENCES
96 -- `PERSON` (`SSN`))
87 97 ROLLBACK; ROLLBACK;
88 98
89 99 -- end snippet solution4 -- end snippet solution4
 
... ... SELECT Address
106 106 FROM HOUSE; FROM HOUSE;
107 107
108 108 -- … the SSN of the persons whose first name was not -- … the SSN of the persons whose first name was not
109 -- entered in the system (000-00-0000).
109 110 SELECT SSN SELECT SSN
110 111 FROM PERSON FROM PERSON
111 112 WHERE FName IS NULL; WHERE FName IS NULL;
 
... ... SELECT DISTINCT COLOR
116 116 FROM HOUSE; FROM HOUSE;
117 117
118 118 -- … the address of the residency of James Baldwin (123 -- … the address of the residency of James Baldwin (123
119 -- Main St.).
119 120 SELECT House SELECT House
120 121 FROM RESIDENCY, PERSON FROM RESIDENCY, PERSON
121 122 WHERE PERSON.Fname = "James" WHERE PERSON.Fname = "James"
 
... ... WHERE PERSON.Fname = "James"
124 124 AND PERSON.SSN = RESIDENCY.Person; AND PERSON.SSN = RESIDENCY.Person;
125 125
126 126 -- … the first name of the oldest person in the database -- … the first name of the oldest person in the database
127 -- (James).
127 128 SELECT FName SELECT FName
128 129 FROM PERSON FROM PERSON
129 130 WHERE Birthdate = ( WHERE Birthdate = (
 
... ... WHERE Birthdate = (
133 133 WHERE Birthdate IS NOT NULL); WHERE Birthdate IS NOT NULL);
134 134
135 135 -- … Michael Keal’s principal residency address (123 Main -- … Michael Keal’s principal residency address (123 Main
136 -- St.).
136 137 SELECT RESIDENCY.House SELECT RESIDENCY.House
137 138 FROM RESIDENCY, PERSON FROM RESIDENCY, PERSON
138 139 WHERE PERSON.FName = "Michael" WHERE PERSON.FName = "Michael"
 
... ... WHERE PERSON.FName = "Michael"
142 142 AND RESIDENCY.PrincipalResidence = TRUE; AND RESIDENCY.PrincipalResidence = TRUE;
143 143
144 144 -- … the (distinct) first and last names of the homeowners -- … the (distinct) first and last names of the homeowners
145 -- (Michael Keal, Mridula Warrier).
145 146 SELECT DISTINCT (PERSON.FName), PERSON.LName SELECT DISTINCT (PERSON.FName), PERSON.LName
146 147 FROM PERSON, RESIDENCY FROM PERSON, RESIDENCY
147 148 WHERE RESIDENCY.Status = "own" WHERE RESIDENCY.Status = "own"
 
... ... WHERE SSN IN ( SELECT DISTINCT (RESIDENCY.Person)
156 156 WHERE RESIDENCY.Status = "own"); WHERE RESIDENCY.Status = "own");
157 157
158 158 -- … the SSN of the persons that have the same principal -- … the SSN of the persons that have the same principal
159 -- residency as James Baldwin (000-00-0001).
159 160 SELECT RoomMate.Person SELECT RoomMate.Person
160 161 FROM RESIDENCY AS James, RESIDENCY AS RoomMate, PERSON FROM RESIDENCY AS James, RESIDENCY AS RoomMate, PERSON
161 162 WHERE PERSON.FName = "James" WHERE PERSON.FName = "James"
 
... ... WHERE PERSON.FName = "James"
170 170 START TRANSACTION; START TRANSACTION;
171 171
172 172 -- start snippet homonyms -- start snippet homonyms
173 -- If we have homonymns in our database, e.g.
173 174 INSERT INTO PERSON INSERT INTO PERSON
174 175 VALUES ("A", "B", "000-00-0010", NULL), ("A", "B", VALUES ("A", "B", "000-00-0010", NULL), ("A", "B",
175 176 "000-00-0011", NULL); "000-00-0011", NULL);
 
... ... INSERT INTO RESIDENCY
184 184 "H", TRUE, "own"); "H", TRUE, "own");
185 185
186 186 -- Then the query below fails, in the sense that it reports -- Then the query below fails, in the sense that it reports
187 -- the name "A, B" only once.
187 188 SELECT DISTINCT (PERSON.FName), PERSON.LName SELECT DISTINCT (PERSON.FName), PERSON.LName
188 189 FROM PERSON, RESIDENCY FROM PERSON, RESIDENCY
189 190 WHERE RESIDENCY.Status = "own" WHERE RESIDENCY.Status = "own"
190 191 AND RESIDENCY.Person = PERSON.SSN; AND RESIDENCY.Person = PERSON.SSN;
191 192
192 193 -- A better (and not much more complicated) solution would -- A better (and not much more complicated) solution would
194 -- have been
193 195 SELECT PERSON.FName, PERSON.LName SELECT PERSON.FName, PERSON.LName
194 196 FROM PERSON FROM PERSON
195 197 WHERE SSN IN ( SELECT DISTINCT (RESIDENCY.Person) WHERE SSN IN ( SELECT DISTINCT (RESIDENCY.Person)
File notes/code/sql/HW_SocialMedia.sql changed (mode: 100644) (index 965e270..acdb22b)
... ... INSERT INTO SUBSCRIBE
39 39 "2019-03-03"), (1, 2, DATE "2019-03-03"); "2019-03-03"), (1, 2, DATE "2019-03-03");
40 40
41 41 -- The first entry means that 2 subscribed to 1, not the -- The first entry means that 2 subscribed to 1, not the
42 -- other way around.
43 -- And similarly for the other entries.
42 44 INSERT INTO VIDEO INSERT INTO VIDEO
43 45 VALUES (10, "My first video!", DATE "2020-02-02", 1), VALUES (10, "My first video!", DATE "2020-02-02", 1),
44 46 (20, "My second video!", DATE "2020-02-03", 1), (30, (20, "My second video!", DATE "2020-02-03", 1), (30,
 
... ... INSERT INTO THUMBS_UP
63 63 -- start snippet solution -- start snippet solution
64 64 /* code/sql/HW_SocialMedia.sql */ /* code/sql/HW_SocialMedia.sql */
65 65 -- … the title of all the videos ("My first video!", "My -- … the title of all the videos ("My first video!", "My
66 -- second video!", "My vacations").
66 67 SELECT TITLE SELECT TITLE
67 68 FROM VIDEO; FROM VIDEO;
68 69
69 70 -- … the release date of the video whose title is "My first -- … the release date of the video whose title is "My first
71 -- video!" ("2020-02-02").
70 72 SELECT Released SELECT Released
71 73 FROM VIDEO FROM VIDEO
72 74 WHERE Title = "My first video!"; WHERE Title = "My first video!";
73 75
74 76 -- … the ID of the account(s) where the "Name" attribute -- … the ID of the account(s) where the "Name" attribute
77 -- was not given ("2").
75 78 SELECT ID SELECT ID
76 79 FROM ACCOUNT FROM ACCOUNT
77 80 WHERE Name IS NULL; WHERE Name IS NULL;
78 81
79 82 -- … the ID of the videos whose title contains the word -- … the ID of the videos whose title contains the word
83 -- "video" ("10", "20").
80 84 SELECT ID SELECT ID
81 85 FROM VIDEO FROM VIDEO
82 86 WHERE TITLE LIKE "%video%"; WHERE TITLE LIKE "%video%";
 
... ... FROM VIDEO
91 91 WHERE Title REGEXP 'video'; WHERE Title REGEXP 'video';
92 92
93 93 -- … the number of thumbs up for the video with title "My -- … the number of thumbs up for the video with title "My
94 -- vacations" ("1").
94 95 SELECT COUNT(*) SELECT COUNT(*)
95 96 FROM THUMBS_UP, VIDEO FROM THUMBS_UP, VIDEO
96 97 WHERE VIDEO.Title = "My vacations" WHERE VIDEO.Title = "My vacations"
 
... ... ORDER BY Released ASC
118 118 LIMIT 1; LIMIT 1;
119 119
120 120 -- … the names of the accounts who gave a thumbs up to the -- … the names of the accounts who gave a thumbs up to the
121 -- video with id 30 ("Bob Ross").
121 122 SELECT Name SELECT Name
122 123 FROM ACCOUNT, THUMBS_UP FROM ACCOUNT, THUMBS_UP
123 124 WHERE THUMBS_UP.Video = 30 WHERE THUMBS_UP.Video = 30
124 125 AND THUMBS_UP.Account = ACCOUNT.ID; AND THUMBS_UP.Account = ACCOUNT.ID;
125 126
126 127 -- … the ID of the account with the greatest number of -- … the ID of the account with the greatest number of
128 -- subscribers ("2").
127 129 SELECT Subscribed SELECT Subscribed
128 130 FROM SUBSCRIBE FROM SUBSCRIBE
129 131 GROUP BY Subscribed GROUP BY Subscribed
File notes/code/sql/HW_Storm.sql changed (mode: 100644) (index e33b79e..4e65b8b)
... ... INSERT INTO STORM
29 29 VALUES ("Harvey", "Hurricane", 130, "2017-08-17"); VALUES ("Harvey", "Hurricane", 130, "2017-08-17");
30 30
31 31 -- In the following, the entry gets created, but date is -- In the following, the entry gets created, but date is
32 -- "corrected" to "2017-17-08"!
33 -- INSERT INTO STORM
34 -- VALUES ("Dummy", "Hurricane", 120, "2017-17-08");
35 -- The error message returned is
36 -- ERROR 1292 (22007) at line 34: Incorrect date value:
37 -- "2017-17-08" for column `HW_STORM`.`STORM`.`Creation`
38 -- at
39 -- row 1
40 -- In the following, we explicitely use "DATE", and
41 -- since
42 -- the date is incorrect, nothing gets inserted.
43 -- INSERT INTO STORM
44 -- VALUES ("Dummy2", "Hurricane", 120, DATE
45 -- "2017-17-08");
46 -- ERROR 1525 (HY000) at line 40: Incorrect DATE value:
47 -- "2017-17-08"
48 -- The next one sets NULL for DATE.
32 49 INSERT INTO STORM INSERT INTO STORM
33 50 VALUES ("Irma", "Tropical Storm", 102, DEFAULT); VALUES ("Irma", "Tropical Storm", 102, DEFAULT);
34 51
 
... ... INSERT INTO STATE
60 61 VALUES ("Florida", "FL", NULL); VALUES ("Florida", "FL", NULL);
61 62
62 63 -- This instruction is not using the primary key, is that a -- This instruction is not using the primary key, is that a
64 -- problem?
63 65 UPDATE UPDATE
64 66 STATE STATE
65 67 SET Affected_by = "Harvey" SET Affected_by = "Harvey"
File notes/code/sql/HW_TriggerExample.sql changed (mode: 100644) (index c5ddeb3..3af2ce5)
2 2 DROP SCHEMA IF EXISTS HW_TriggerExample; DROP SCHEMA IF EXISTS HW_TriggerExample;
3 3
4 4 -- To drop only a trigger, you can use -- To drop only a trigger, you can use
5 -- DROP TRIGGER IF EXISTS
6 -- HW_TriggerExample.NUMBER_OF_STUDENT_INC;
7 -- DROP TRIGGER IF EXISTS
8 -- HW_TriggerExample.NUMBER_OF_STUDENT_DEC;
5 9 CREATE SCHEMA HW_TriggerExample; CREATE SCHEMA HW_TriggerExample;
6 10
7 11 USE HW_TriggerExample; USE HW_TriggerExample;
 
... ... CREATE TRIGGER STUDENT_AVERAGE
72 72 WHERE STUDENT.Login = NEW.Student; WHERE STUDENT.Login = NEW.Student;
73 73
74 74 -- The "NEW" keyword here refers to the "new" entry -- The "NEW" keyword here refers to the "new" entry
75 -- that is being inserted by the INSERT statement
76 -- triggering
77 -- the trigger.
78 -- end snippet trigger-3
75 79 INSERT INTO GRADE INSERT INTO GRADE
76 80 VALUES ("A", "Exam 1", 50), ("A", "Exam 2", 40), ("B", VALUES ("A", "Exam 1", 50), ("A", "Exam 2", 40), ("B",
77 81 "Exam 1", 80), ("B", "Exam 2", 100); "Exam 1", 80), ("B", "Exam 2", 100);
 
... ... SELECT *
87 87 FROM STUDENT; FROM STUDENT;
88 88
89 89 -- Tada, all the averages have been computed! -- Tada, all the averages have been computed!
90 -- Note also that the student "C" does not have an
91 -- average!
File notes/code/sql/HW_Work.sql changed (mode: 100644) (index 543f0bf..a596b78)
... ... INSERT INTO EBOOK
78 78 So, "Successful insertion". So, "Successful insertion".
79 79 */ */
80 80 -- The following statement raises an error. -- The following statement raises an error.
81 -- INSERT INTO AUTHOR
82 -- VALUES ("Mary B.", "mb@fai.fr", NULL);
81 83 /* /*
82 84 ERROR 1136 (21S01): Column count doesn't match value count at row 1 ERROR 1136 (21S01): Column count doesn't match value count at row 1
83 85 So, "Other kind of error". So, "Other kind of error".
84 86 */ */
85 87 -- The following statement raises an error. -- The following statement raises an error.
88 -- INSERT INTO WORK
89 -- VALUES ("My Life", "Claude A.");
86 90 /* /*
87 91 ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
88 92 (`HW_EXAM_1`.`WORK`, CONSTRAINT `WORK_ibfk_1` FOREIGN KEY (`Author`) REFERENCES `AUTHOR` (`Name`) (`HW_EXAM_1`.`WORK`, CONSTRAINT `WORK_ibfk_1` FOREIGN KEY (`Author`) REFERENCES `AUTHOR` (`Name`)
 
... ... INSERT INTO BOOK
102 102 So, "Successful insertion". So, "Successful insertion".
103 103 */ */
104 104 -- The following statement raises an error. -- The following statement raises an error.
105 -- INSERT INTO AUTHOR
106 -- VALUES ("Virginia W.", "alt@isp.net");
105 107 /* /*
106 108 ERROR 1062 (23000): Duplicate entry 'Virginia W.' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry 'Virginia W.' for key 'PRIMARY'
107 109 So, "Entity integrity constraint". So, "Entity integrity constraint".
 
... ... WHERE Title = "What to eat";
149 149 Does not change any row. Does not change any row.
150 150 */ */
151 151 -- The following statement raises an error. -- The following statement raises an error.
152 -- DELETE FROM AUTHOR
153 -- WHERE Name = "Virginia W.";
152 154 /* /*
153 155 ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
154 156 (`HW_EXAM_1`.`BOOK`, CONSTRAINT `BOOK_ibfk_1` FOREIGN KEY (`Work`) REFERENCES `WORK` (`Title`) ON UPDATE CASCADE) (`HW_EXAM_1`.`BOOK`, CONSTRAINT `BOOK_ibfk_1` FOREIGN KEY (`Work`) REFERENCES `WORK` (`Title`) ON UPDATE CASCADE)
 
... ... WHERE Title = "What to eat";
159 159 ROLLBACK; ROLLBACK;
160 160
161 161 -- We go back to the previous state. -- We go back to the previous state.
162 -- You can now assume that there is more data than what
163 -- we
164 -- inserted, if that helps you. Write a command that
165 -- selects
166 -- …
167 -- We insert some dummy values for this next part.
162 168 INSERT INTO WORK INSERT INTO WORK
163 169 VALUES ("My Life", "Paul B."), ("What to eat, 2", "Virginia W."); VALUES ("My Life", "Paul B."), ("What to eat, 2", "Virginia W.");
164 170
 
... ... SELECT Price
181 181 FROM EBOOK; FROM EBOOK;
182 182
183 183 -- … the (distinct) names of the authors who have authored -- … the (distinct) names of the authors who have authored
184 -- a piece of work.
184 185 SELECT DISTINCT Author SELECT DISTINCT Author
185 186 FROM WORK; FROM WORK;
186 187
 
... ... SELECT MAX(Price)
207 207 FROM BOOK; FROM BOOK;
208 208
209 209 -- … the number of pieces of work written by the author -- … the number of pieces of work written by the author
210 -- whose name is “Virginia W.”.
210 211 SELECT COUNT(*) SELECT COUNT(*)
211 212 FROM WORK FROM WORK
212 213 WHERE WORK.Author = "Virginia W."; WHERE WORK.Author = "Virginia W.";
213 214
214 215 -- … the email of the author who wrote the piece of work -- … the email of the author who wrote the piece of work
216 -- called “My Life”.
215 217 SELECT Email SELECT Email
216 218 FROM AUTHOR, WORK FROM AUTHOR, WORK
217 219 WHERE WORK.Title = "My Life" WHERE WORK.Title = "My Life"
218 220 AND WORK.Author = AUTHOR.Name; AND WORK.Author = AUTHOR.Name;
219 221
220 222 -- the isbn(s) of the book containing a work written by the -- the isbn(s) of the book containing a work written by the
223 -- author whose email is "vw@isp.net".
221 224 SELECT ISBN SELECT ISBN
222 225 FROM BOOK, WORK, AUTHOR FROM BOOK, WORK, AUTHOR
223 226 WHERE AUTHOR.Email = "vw@isp.net" WHERE AUTHOR.Email = "vw@isp.net"
 
... ... WHERE
246 246 they are both given the title "BANNED", which violates the unicity of value in primary keys. they are both given the title "BANNED", which violates the unicity of value in primary keys.
247 247 */ */
248 248 -- Write one or multiple commands that would delete the work -- Write one or multiple commands that would delete the work
249 -- whose title is “My Life”, as well as all of the
250 -- books
251 -- and ebooks versions of it.
252 -- The following statement raises an error.
253 -- DELETE FROM WORK
254 -- WHERE Title = "My Life";
249 255 /* /*
250 256 Fails Fails
251 257 ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
File notes/lectures_notes.md changed (mode: 100644) (index 6d87395..3ef58dd)
... ... And we can even specify the order (even the trivial one):
1970 1970
1971 1971 Note the date literals. Note the date literals.
1972 1972
1973 ### A Bit More on Foreign Keys
1974
1975 Note that we can create foreign keys to primary keys made of multiple attributes, and to the primary key of the table we are currently creating.
1976
1977 ```{.sqlmysql .numberLines include=code/sql/HW_AdvancedFK.sql snippet=advancedFK}
1978 ```
1979
1973 1980 ## A First Look at Conditions ## A First Look at Conditions
1974 1981
1975 1982 Order of clauses does not matter, not even for optimization purpose. Order of clauses does not matter, not even for optimization purpose.
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