List of commits:
Subject Hash Author Date (UTC)
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
Updated spots to https. a8daf1768395aa296bf0dd05783dd53c757d5d19 aubert@math.cnrs.fr 2020-10-05 16:18:44
Adding quiz #2 98e0ae5b8ce766524f60c91adb1040235e1bbf31 aubert@math.cnrs.fr 2020-10-02 19:00:15
Added exam 1 e2f62ae4bf26fcc4b86e8665060ccf3918e7abeb aubert@math.cnrs.fr 2020-09-24 12:51:36
worked on solution to first exam. b13ad99dd895f124df1b642fd990071fc09db294 aubert@math.cnrs.fr 2020-09-23 17:44:01
Added solution to first problem. 0948cee47ed78dc115fd69c7bcf96a312dd3162f aubert@math.cnrs.fr 2020-09-18 21:43:00
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
Commit 09a6a78479f24b5749605a4cb7136f8cfbf57d30 - Fixed url in comments, avoid them being wrapped.
Author: aubert@math.cnrs.fr
Author date (UTC): 2020-12-18 18:55
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2020-12-18 18:55
Parent(s): f3e9c2abac41d5de1c7473867c4f688051dec928
Signer:
Signing key:
Signing status: N
Tree: 65fd444197ceee92b93144a8fb68358a48c75cdf
File Lines added Lines deleted
install/INSTALL.md 0 2
notes/Makefile 1 2
notes/code/java/SimpleInjection01.java 1 1
notes/code/sql/HW_AdvancedFK.sql 15 14
notes/code/sql/HW_Capstone.sql 1 3
notes/code/sql/HW_CapstoneSol.sql 43 44
notes/code/sql/HW_Certificate.sql 29 27
notes/code/sql/HW_ConstraintsPart1.sql 1 1
notes/code/sql/HW_DBCoffee.sql 13 12
notes/code/sql/HW_Department.sql 1 1
notes/code/sql/HW_Faculty.sql 1 1
notes/code/sql/HW_ProcedureExamples.sql 4 3
notes/code/sql/HW_ProfExample.sql 2 2
notes/code/sql/HW_ResidencySol.sql 25 25
notes/code/sql/HW_ScientificResearchSol.sql 27 22
notes/code/sql/HW_SocialMedia.sql 9 9
notes/code/sql/HW_Storm.sql 23 23
notes/code/sql/HW_TriggerExample.sql 12 10
notes/code/sql/HW_Work.sql 30 27
File install/INSTALL.md changed (mode: 100644) (index c2dbc3c..18ea7f0)
... ... To compile [those notes](../README.html), you need
21 21 - librsvg2-bin, - librsvg2-bin,
22 22 - font-linuxlibertine - font-linuxlibertine
23 23
24 **Warning: as of now (Nov. 2020), you actually need [pandoc 2.9.2.1](https://github.com/jgm/pandoc/releases/tag/2.9.2.1),
25
26 24 Then, clone the repository at <https://rocketgit.com/user/caubert/CSCI_3410>, and refer to [the example file](../notes/example.html) for a gentle test and guide on the syntax and tool of this document. Then, clone the repository at <https://rocketgit.com/user/caubert/CSCI_3410>, and refer to [the example file](../notes/example.html) for a gentle test and guide on the syntax and tool of this document.
27 25 Change the current folder to `notes`, and execute `make example`. Change the current folder to `notes`, and execute `make example`.
28 26 You can have a look at `notes/Makefile` to understand what is happening in the `example` rule. You can have a look at `notes/Makefile` to understand what is happening in the `example` rule.
File notes/Makefile changed (mode: 100644) (index 3b72f7d..01fde7c)
4 4
5 5 # http://www.gnu.org/software/make/manual/make.html # http://www.gnu.org/software/make/manual/make.html
6 6 # http://nuclear.mutantstargoat.com/articles/make/ # http://nuclear.mutantstargoat.com/articles/make/
7 # http://nuclear.mutantstargoat.com/articles/make/
8 7
9 8
10 9 ########################### ###########################
 
... ... $(JAVA_CODE):
134 133 .PHONY: clean_sql $(SQL_CODE) .PHONY: clean_sql $(SQL_CODE)
135 134 clean_sql: $(SQL_CODE) clean_sql: $(SQL_CODE)
136 135 $(SQL_CODE): $(SQL_CODE):
137 pg_format -s 2 -t -U 2 -w 60 -W 1 -C -B -i $@
136 pg_format -s 2 -t -U 2 -w 60 -W 1 -C -B -p 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' -i $@
138 137
139 138 ### ###
140 139 # Rules to call makefile from parent directory. # Rules to call makefile from parent directory.
File notes/code/java/SimpleInjection01.java changed (mode: 100644) (index 30302c4..1f9bd79)
... ... public class SimpleInjection01 {
41 41 stmt.executeQuery("SELECT * FROM SECRETVIP WHERE Name ='" + entered + "';"); stmt.executeQuery("SELECT * FROM SECRETVIP WHERE Name ='" + entered + "';");
42 42 // end snippet gist // end snippet gist
43 43 if (rset.next()) { if (rset.next()) {
44 System.out.print("Yes," + rset.getString(1) + " is our secret VIP!\n");
44 System.out.print("Yes, " + rset.getString(1) + " is our secret VIP!\n");
45 45 } else { } else {
46 46 System.out.print("Nope, \"" + entered + "\" is not our secret VIP.\n"); System.out.print("Nope, \"" + entered + "\" is not our secret VIP.\n");
47 47 } }
File notes/code/sql/HW_AdvancedFK.sql changed (mode: 100644) (index ec81722..23b22d7)
... ... CREATE TABLE T2 (
19 19 B1 INT PRIMARY KEY, B1 INT PRIMARY KEY,
20 20 B2 INT, B2 INT,
21 21 -- We can create a "pair" of foreign key in one line, as -- We can create a "pair" of foreign key in one line, as
22 -- follows:
22 -- follows:
23 23 FOREIGN KEY (A1, A2) REFERENCES T1 (A1, A2), FOREIGN KEY (A1, A2) REFERENCES T1 (A1, A2),
24 24 -- We can create a foreign key that references the primary -- We can create a foreign key that references the primary
25 -- key of the table we are currently creating, and name
26 -- it,
27 -- as follows:
25 -- key of the table we are currently creating, and
26 -- name
27 -- it,
28 -- as follows:
28 29 CONSTRAINT My_pk_to_T1 FOREIGN KEY (B2) REFERENCES T2 (B1) CONSTRAINT My_pk_to_T1 FOREIGN KEY (B2) REFERENCES T2 (B1)
29 30 ); );
30 31
31 32 -- The benefit of naming our fk constraint is that, if we -- The benefit of naming our fk constraint is that, if we
32 -- INSERT INTO T2 VALUES (1, 1, 1, 3);
33 -- then the name of the constraint (here
34 -- Cannot add or update a child row: a foreign key
35 -- end snippet advancedFK
33 -- violate it, for instance with
34 -- INSERT INTO T2 VALUES (1, 1, 1, 3);
35 -- then the name of the constraint (here
36 -- "My_pk_to_T1")
37 -- would be displayed in the error message:
38 -- Cannot add or update a child row: a foreign key
39 -- constraint fails (`db_9_9837c1`.`t2`, CONSTRAINT
40 -- `My_pk_to_T1` FOREIGN KEY (`B2`) REFERENCES `t2`
41 -- (`B1`))
42 -- end snippet advancedFK
File notes/code/sql/HW_Capstone.sql changed (mode: 100644) (index 062b8b8..5dea9d4)
... ... VALUES (
74 74 "PSF"); "PSF");
75 75
76 76 -- Taken from -- Taken from
77 -- https://en.wikipedia.org/wiki/Comparison_of_open-source_programming_language_licensing
77 78 INSERT INTO PROJECT INSERT INTO PROJECT
78 79 VALUES ( VALUES (
79 80 "Brick Break", "Brick Break",
File notes/code/sql/HW_CapstoneSol.sql changed (mode: 100644) (index 0139319..1c14b77)
... ... VALUES (
74 74 "PSF"); "PSF");
75 75
76 76 -- Taken from -- Taken from
77 -- https://en.wikipedia.org/wiki/Comparison_of_open-source_programming_language_licensing
77 78 INSERT INTO PROJECT INSERT INTO PROJECT
78 79 VALUES ( VALUES (
79 80 "Brick Break", "Brick Break",
 
... ... Answer the following short questions based on the model implemented above.
130 123 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).
131 124 */ */
132 125 -- 1. Can a project uses multiple programming languages? -- 1. Can a project uses multiple programming languages?
133 -- Yes.
134 -- 2. Can a student be the leader of multiple
135 -- Yes.
136 -- 3. Can multiple projects have the same code name?
137 -- Yes.
138 -- 4. Could Claude simply enter NULL for the value of
139 -- No.
140 -- 5. Can a project be created without project leader?
141 -- No.
142 -- 6. Can we know who is working on a project without
143 -- No.
126 -- Yes.
127 -- 2. Can a student be the leader of multiple
128 -- projects?
129 -- Yes.
130 -- 3. Can multiple projects have the same code name?
131 -- Yes.
132 -- 4. Could Claude simply enter NULL for the value
133 -- of
134 -- his
135 -- project's code name, since he's undecided?
136 -- No.
137 -- 5. Can a project be created without project
138 -- leader?
139 -- No.
140 -- 6. Can we know who is working on a project
141 -- without
142 -- being
143 -- its leader?
144 -- No.
144 145 /* /*
145 146
146 147 II. Relational Model (6 pts.) II. Relational Model (6 pts.)
 
... ... Please, leave them uncommented, unless you can't write them correctly, in which
162 158 The first question is answered as an example. The first question is answered as an example.
163 159 */ */
164 160 -- 0. Write a command that list all the names of the -- 0. Write a command that list all the names of the
161 -- programming languages.
165 162 SELECT Name SELECT Name
166 163 FROM PROGRAMMING_LANGUAGE; FROM PROGRAMMING_LANGUAGE;
167 164
168 165 -- 1. Write a command that insert a new student in the -- 1. Write a command that insert a new student in the
169 -- (You should invent the values).
166 -- STUDENT table.
167 -- (You should invent the values).
170 168 INSERT INTO STUDENT INSERT INTO STUDENT
171 169 VALUES ( VALUES (
172 170 "Bob", "Bob",
 
... ... VALUES (
177 173 NULL); NULL);
178 174
179 175 -- 2. Write a command that updates the code name of the -- 2. Write a command that updates the code name of the
176 -- project ("Undecided", "9999999999999") to "VR in
177 -- ER".
180 178 UPDATE UPDATE
181 179 PROJECT PROJECT
182 180 SET CodeName = "VR in ER" SET CodeName = "VR in ER"
 
... ... WHERE CodeName = "Undecided"
186 182 AND Leader = "9999999999999"; AND Leader = "9999999999999";
187 183
188 184 -- 3. Write a command that updates the graduation year of the -- 3. Write a command that updates the graduation year of the
185 -- student whose id is "0987654321098" to 2024, and
186 -- the
187 -- semester to "Fall".
189 188 UPDATE UPDATE
190 189 STUDENT STUDENT
191 190 SET GraduationYear = 2024, SET GraduationYear = 2024,
 
... ... SET GraduationYear = 2024,
195 192 WHERE id = "0987654321098"; WHERE id = "0987654321098";
196 193
197 194 -- 4. Write a command that changes the STUDENT table to make -- 4. Write a command that changes the STUDENT table to make
195 -- it impossible to enter NULL for the first name of
196 -- a
197 -- student, without changing the primary key.
198 198 ALTER TABLE STUDENT MODIFY FName VARCHAR(50) NOT NULL; ALTER TABLE STUDENT MODIFY FName VARCHAR(50) NOT NULL;
199 199
200 200 -- 5. Write a command that changes the datatype of -- 5. Write a command that changes the datatype of
201 -- GraduationYear to SMALLINT.
201 202 ALTER TABLE STUDENT MODIFY GraduationYear SMALLINT; ALTER TABLE STUDENT MODIFY GraduationYear SMALLINT;
202 203
203 204 -- 6. Write a command that adds an attribute "ReleaseDate" to -- 6. Write a command that adds an attribute "ReleaseDate" to
205 -- the PROJECT table.
204 206 ALTER TABLE PROJECT ALTER TABLE PROJECT
205 207 ADD COLUMN ReleaseDate DATE; ADD COLUMN ReleaseDate DATE;
206 208
207 209 -- 6.bis If you managed to write the previous command -- 6.bis If you managed to write the previous command
210 -- correctly, write a command that sets the release
211 -- date
212 -- of
213 -- the project ("Brick Break", "0123456789100") to
214 -- the
215 -- 26th
216 -- of November 2022.
208 217 UPDATE UPDATE
209 218 PROJECT PROJECT
210 219 SET ReleaseDate = DATE "20221126" SET ReleaseDate = DATE "20221126"
 
... ... WHERE CodeName = "Brick Break"
222 221 AND Leader = "0123456789100"; AND Leader = "0123456789100";
223 222
224 223 -- 7. Write a command that makes it impossible for a student -- 7. Write a command that makes it impossible for a student
225 -- (This command should return an error)
226 -- ALTER TABLE PROJECT ADD UNIQUE (Leader);
224 -- to be the leader in more than one project
225 -- (This command should return an error)
226 -- ALTER TABLE PROJECT ADD UNIQUE (Leader);
File notes/code/sql/HW_Certificate.sql changed (mode: 100644) (index 03e33ff..8461e9e)
... ... SELECT CN
91 91 FROM CERTIFICATE; FROM CERTIFICATE;
92 92
93 93 -- (*.wikimedia.org | *.fsf.org | *.shadytest.org | -- (*.wikimedia.org | *.fsf.org | *.shadytest.org |
94 -- *.wikipedia.org)
95 -- The SN of the organizations whose CN contains
96 -- "Foundation"
94 -- *.wikipedia.org)
95 -- The SN of the organizations whose CN contains
96 -- "Foundation"
97 97 SELECT SN SELECT SN
98 98 FROM ORGANIZATION FROM ORGANIZATION
99 99 WHERE CN LIKE "%Foundation%"; WHERE CN LIKE "%Foundation%";
100 100
101 101 -- (01 | 02) -- (01 | 02)
102 -- The CN and expiration date of all the
103 -- that
104 -- expired (assuming we are the 6th of December
102 -- The CN and expiration date of all the
103 -- certificates
104 -- that
105 -- expired (assuming we are the 6th of December
106 -- 2019).
105 107 SELECT CN, SELECT CN,
106 108 Valid_Until Valid_Until
107 109 FROM CERTIFICATE FROM CERTIFICATE
108 110 WHERE Valid_Until < DATE '20191206'; WHERE Valid_Until < DATE '20191206';
109 111
110 112 -- (*.fsf.org, 2019-10-10) -- (*.fsf.org, 2019-10-10)
111 -- The CN of the CA that are not trusted.
113 -- The CN of the CA that are not trusted.
112 114 SELECT CN SELECT CN
113 115 FROM CA FROM CA
114 116 WHERE Trusted IS NOT TRUE; WHERE Trusted IS NOT TRUE;
115 117
116 118 -- (Shady Corp. | NewComer Ltd.) -- (Shady Corp. | NewComer Ltd.)
117 -- The CN of the certificates that are signed by a
118 -- that
119 -- is not trusted.
119 -- The CN of the certificates that are signed by
120 -- a
121 -- CA
122 -- that
123 -- is not trusted.
120 124 SELECT CERTIFICATE.CN SELECT CERTIFICATE.CN
121 125 FROM CERTIFICATE, FROM CERTIFICATE,
122 126 CA CA
 
... ... WHERE Trusted IS NOT TRUE
127 128 AND CA.SN = CERTIFICATE.Issuer; AND CA.SN = CERTIFICATE.Issuer;
128 129
129 130 -- (Shady Corp. | NewComer Ltd.) -- (Shady Corp. | NewComer Ltd.)
130 -- The number of certificates signed by the CA
131 -- is
132 -- "Let's encrypt".
131 -- The number of certificates signed by the CA
132 -- whose
133 -- CN
134 -- is
135 -- "Let's encrypt".
133 136 SELECT COUNT(CERTIFICATE.SN) AS "Number of certificates signed SELECT COUNT(CERTIFICATE.SN) AS "Number of certificates signed
134 137 by Let's encrypt" by Let's encrypt"
135 138 FROM CERTIFICATE, FROM CERTIFICATE,
 
... ... WHERE CERTIFICATE.Issuer = CA.SN
140 141 AND CA.CN = "Let's encrypt"; AND CA.CN = "Let's encrypt";
141 142
142 143 -- (2) -- (2)
143 -- A table listing the CN of the organizations
144 -- the CN of their certificates.
144 -- A table listing the CN of the organizations
145 -- along
146 -- with
147 -- the CN of their certificates.
145 148 SELECT ORGANIZATION.CN AS Organization, SELECT ORGANIZATION.CN AS Organization,
146 149 CERTIFICATE.CN AS Certificate CERTIFICATE.CN AS Certificate
147 150 FROM ORGANIZATION, FROM ORGANIZATION,
 
... ... FROM ORGANIZATION,
151 152 WHERE CERTIFICATE.Org = ORGANIZATION.SN; WHERE CERTIFICATE.Org = ORGANIZATION.SN;
152 153
153 154 -- ( Wikimedia Foundation, *.wikimedia.org | Free Software -- ( Wikimedia Foundation, *.wikimedia.org | Free Software
154 -- Foundation, *.fsf.org | Free Software Foundation
155 -- *.shadytest.org | Wikimedia Foundation ,
156 -- *.wikipedia.org
157 -- )
155 -- Foundation, *.fsf.org | Free Software
156 -- Foundation
157 -- ,
158 -- *.shadytest.org | Wikimedia Foundation ,
159 -- *.wikipedia.org
160 -- )
158 161 /* /*
159 162 DELETE FROM CA WHERE SN = 'A'; DELETE FROM CA WHERE SN = 'A';
160 163 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 0f5cc26..c5619e8)
... ... CREATE TABLE HURRICANE (
10 10 WindSpeed INT DEFAULT 76 CHECK (WindSpeed > 74 AND WindSpeed INT DEFAULT 76 CHECK (WindSpeed > 74 AND
11 11 WindSpeed < 500), WindSpeed < 500),
12 12 -- 75mph is the minimum to be considered as a hurricane -- 75mph is the minimum to be considered as a hurricane
13 -- cf. https://www.hwn.org/resources/bws.html
13 -- cf. https://www.hwn.org/resources/bws.html
14 14 Above VARCHAR(25) Above VARCHAR(25)
15 15 ); );
16 16
File notes/code/sql/HW_DBCoffee.sql changed (mode: 100644) (index 3c543c1..4462200)
... ... VALUES (
125 125 3.00); 3.00);
126 126
127 127 -- The following statement raises an error. -- The following statement raises an error.
128 -- INSERT INTO PROVIDER
129 -- VALUES (NULL, "contact@localcof.com");
130 -- ERROR 1048 (23000) at line 68: Column 'Name'
131 -- null
128 -- INSERT INTO PROVIDER
129 -- VALUES (NULL, "contact@localcof.com");
130 -- ERROR 1048 (23000) at line 68: Column 'Name'
131 -- cannot
132 -- be
133 -- null
132 134 INSERT INTO SUPPLY INSERT INTO SUPPLY
133 135 VALUES ( VALUES (
134 136 "Johns & Co.", "Johns & Co.",
135 137 121); 121);
136 138
137 139 -- The following statement raises an error. -- The following statement raises an error.
138 -- -INSERT INTO SUPPLY
139 -- VALUES ("Coffee Unl.", 311, 221);
140 -- ERROR 1136 (21S01): Column count doesn't match
141 -- count at row 1
142 -- Rest the changes:
140 -- -INSERT INTO SUPPLY
141 -- VALUES ("Coffee Unl.", 311, 221);
142 -- ERROR 1136 (21S01): Column count doesn't
143 -- match
144 -- value
145 -- count at row 1
146 -- Rest the changes:
143 147 ROLLBACK; ROLLBACK;
144 148
145 149 -- Question 3: -- Question 3:
File notes/code/sql/HW_Department.sql changed (mode: 100644) (index 4d17f1f..3ed6152)
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 -- exists already, and all the data in it.
9 9 CREATE SCHEMA HW_Department; CREATE SCHEMA HW_Department;
10 10
11 11 -- And then re-creating it. -- And then re-creating it.
File notes/code/sql/HW_Faculty.sql changed (mode: 100644) (index 16a8c1b..df9432e)
... ... VALUES (
68 68 '19940101', -- Or '940101', '1994-01-01', '94/01/01' '19940101', -- Or '940101', '1994-01-01', '94/01/01'
69 69 '090500', -- Or '09:05:00', '9:05:0', '9:5:0', '090500' '090500', -- Or '09:05:00', '9:05:0', '9:5:0', '090500'
70 70 -- Note also the existence of DATETIME, with 'YYYY-MM-DD -- Note also the existence of DATETIME, with 'YYYY-MM-DD
71 -- HH:MM:SS'
71 -- HH:MM:SS'
72 72 'Apple' -- This is not case-sensitive, oddly enough. 'Apple' -- This is not case-sensitive, oddly enough.
73 73 ); );
File notes/code/sql/HW_ProcedureExamples.sql changed (mode: 100644) (index 0a93dae..b287790)
... ... BEGIN
42 42 END; END;
43 43 $$ $$
44 44 -- This is the delimiter that marks the end of the procedure -- This is the delimiter that marks the end of the procedure
45 -- definition.
45 -- definition.
46 46 DELIMITER ; DELIMITER ;
47 47
48 48 -- Now, we want ";" to be the "natural" delimiter again. -- Now, we want ";" to be the "natural" delimiter again.
 
... ... DELIMITER ;
69 69 SHOW CREATE PROCEDURE STUDENTLOGIN; SHOW CREATE PROCEDURE STUDENTLOGIN;
70 70
71 71 -- This display information about the procedure just created. -- This display information about the procedure just created.
72 -- We can pass quite naturally an argument to our
73 -- procedure.
72 -- We can pass quite naturally an argument to
73 -- our
74 -- procedure.
74 75 CALL STUDENTLOGIN ("Test A"); CALL STUDENTLOGIN ("Test A");
75 76
76 77 -- end snippet procedure-3 -- end snippet procedure-3
File notes/code/sql/HW_ProfExample.sql changed (mode: 100644) (index aa42573..297da89)
... ... WHERE DEPARTMENT.Name = "Mathematics"
215 215 AND Department = Code; AND Department = Code;
216 216
217 217 -- end snippet select-project-join-1 -- end snippet select-project-join-1
218 -- start snippet select-project-join-2
218 -- start snippet select-project-join-2
219 219 SELECT Name SELECT Name
220 220 FROM STUDENT, FROM STUDENT,
221 221 GRADE GRADE
 
... ... WHERE Grade > 3.0
223 223 AND STUDENT.Login = GRADE.Login; AND STUDENT.Login = GRADE.Login;
224 224
225 225 -- end snippet select-project-join-2 -- end snippet select-project-join-2
226 -- start snippet select-project-join-3
226 -- start snippet select-project-join-3
227 227 SELECT PROF.Name SELECT PROF.Name
228 228 FROM PROF, FROM PROF,
229 229 DEPARTMENT, DEPARTMENT,
File notes/code/sql/HW_ResidencySol.sql changed (mode: 100644) (index c31ab37..b35d57c)
... ... VALUES (
75 75 the next question. the next question.
76 76 */ */
77 77 -- Exercise 4 -- Exercise 4
78 -- List the rows (i.e., P.2, H.1, or even
79 -- modified by the following statements:
78 -- List the rows (i.e., P.2, H.1, or even
79 -- “none”)
80 -- modified by the following statements:
80 81 START TRANSACTION; START TRANSACTION;
81 82
82 83 UPDATE UPDATE
 
... ... ROLLBACK;
106 106 START TRANSACTION; START TRANSACTION;
107 107
108 108 -- Commented, because it causes an error. -- Commented, because it causes an error.
109 -- DELETE FROM PERSON
110 -- WHERE Birthdate = DATE "1990-02-11";
111 -- None, because of the foreign key and the
112 -- integrity constraint.
113 -- ERROR 1451 (23000): Cannot delete or update a
114 -- row:
115 -- a foreign key constraint fails
116 -- (`HW_RESIDENCY_SOL`.`RESIDENCY`, CONSTRAINT
117 -- `RESIDENCY_ibfk_1` FOREIGN KEY (`Person`)
118 -- `PERSON` (`SSN`))
109 -- DELETE FROM PERSON
110 -- WHERE Birthdate = DATE "1990-02-11";
111 -- None, because of the foreign key and the
112 -- referential
113 -- integrity constraint.
114 -- ERROR 1451 (23000): Cannot delete or update a
115 -- parent
116 -- row:
117 -- a foreign key constraint fails
118 -- (`HW_RESIDENCY_SOL`.`RESIDENCY`, CONSTRAINT
119 -- `RESIDENCY_ibfk_1` FOREIGN KEY (`Person`)
120 -- REFERENCES
121 -- `PERSON` (`SSN`))
119 122 ROLLBACK; ROLLBACK;
120 123
121 124 -- end snippet solution4 -- end snippet solution4
 
... ... SELECT Address
131 131 FROM HOUSE; FROM HOUSE;
132 132
133 133 -- … the SSN of the persons whose first name was not -- … the SSN of the persons whose first name was not
134 -- entered in the system (000-00-0000).
134 -- entered in the system (000-00-0000).
135 135 SELECT SSN SELECT SSN
136 136 FROM PERSON FROM PERSON
137 137 WHERE FName IS NULL; WHERE FName IS NULL;
 
... ... SELECT DISTINCT COLOR
141 141 FROM HOUSE; FROM HOUSE;
142 142
143 143 -- … the address of the residency of James Baldwin (123 -- … the address of the residency of James Baldwin (123
144 -- Main St.).
144 -- Main St.).
145 145 SELECT House SELECT House
146 146 FROM RESIDENCY, FROM RESIDENCY,
147 147 PERSON PERSON
 
... ... WHERE PERSON.Fname = "James"
150 150 AND PERSON.SSN = RESIDENCY.Person; AND PERSON.SSN = RESIDENCY.Person;
151 151
152 152 -- … the first name of the oldest person in the database -- … the first name of the oldest person in the database
153 -- (James).
153 -- (James).
154 154 SELECT FName SELECT FName
155 155 FROM PERSON FROM PERSON
156 156 WHERE Birthdate = ( WHERE Birthdate = (
 
... ... WHERE Birthdate = (
159 159 WHERE Birthdate IS NOT NULL); WHERE Birthdate IS NOT NULL);
160 160
161 161 -- … Michael Keal’s principal residency address (123 Main -- … Michael Keal’s principal residency address (123 Main
162 -- St.).
162 -- St.).
163 163 SELECT RESIDENCY.House SELECT RESIDENCY.House
164 164 FROM RESIDENCY, FROM RESIDENCY,
165 165 PERSON PERSON
 
... ... WHERE PERSON.FName = "Michael"
169 169 AND RESIDENCY.PrincipalResidence = TRUE; AND RESIDENCY.PrincipalResidence = TRUE;
170 170
171 171 -- … the (distinct) first and last names of the homeowners -- … the (distinct) first and last names of the homeowners
172 -- (Michael Keal, Mridula Warrier).
172 -- (Michael Keal, Mridula Warrier).
173 173 SELECT DISTINCT (PERSON.FName), SELECT DISTINCT (PERSON.FName),
174 174 PERSON.LName PERSON.LName
175 175 FROM PERSON, FROM PERSON,
 
... ... WHERE SSN IN ( SELECT DISTINCT (RESIDENCY.Person)
186 186 WHERE RESIDENCY.Status = "own"); WHERE RESIDENCY.Status = "own");
187 187
188 188 -- … the SSN of the persons that have the same principal -- … the SSN of the persons that have the same principal
189 -- residency as James Baldwin (000-00-0001).
189 -- residency as James Baldwin (000-00-0001).
190 190 SELECT RoomMate.Person SELECT RoomMate.Person
191 191 FROM RESIDENCY AS James, FROM RESIDENCY AS James,
192 192 RESIDENCY AS RoomMate, RESIDENCY AS RoomMate,
 
... ... WHERE PERSON.FName = "James"
202 202 START TRANSACTION; START TRANSACTION;
203 203
204 204 -- start snippet homonyms -- start snippet homonyms
205 -- If we have homonymns in our database, e.g.
205 -- If we have homonymns in our database, e.g.
206 206 INSERT INTO PERSON INSERT INTO PERSON
207 207 VALUES ( VALUES (
208 208 "A", "A",
 
... ... VALUES (
234 234 "own"); "own");
235 235
236 236 -- Then the query below fails, in the sense that it reports -- Then the query below fails, in the sense that it reports
237 -- the name "A, B" only once.
237 -- the name "A, B" only once.
238 238 SELECT DISTINCT (PERSON.FName), SELECT DISTINCT (PERSON.FName),
239 239 PERSON.LName PERSON.LName
240 240 FROM PERSON, FROM PERSON,
 
... ... WHERE RESIDENCY.Status = "own"
243 243 AND RESIDENCY.Person = PERSON.SSN; AND RESIDENCY.Person = PERSON.SSN;
244 244
245 245 -- A better (and not much more complicated) solution would -- A better (and not much more complicated) solution would
246 -- have been
246 -- have been
247 247 SELECT PERSON.FName, SELECT PERSON.FName,
248 248 PERSON.LName PERSON.LName
249 249 FROM PERSON FROM PERSON
File notes/code/sql/HW_ScientificResearchSol.sql changed (mode: 100644) (index bed42a7..436dd4f)
... ... VALUES (
103 103 -- start snippet solution -- start snippet solution
104 104 /* code/sql/HW_ScientificResearchSol.sql */ /* code/sql/HW_ScientificResearchSol.sql */
105 105 -- List the rows affected (updated or deleted) by the -- List the rows affected (updated or deleted) by the
106 -- following commands.
107 -- If no rows are affected because the command would would
108 -- violate the entity integrity constraint, the referential
109 -- integrity constraint, or if there would be some other
110 -- kind
111 -- of error, please indicate it.
106 112 START TRANSACTION; START TRANSACTION;
113
114
107 115 /* /*
108 116 UPDATE UPDATE
109 SCIENTIST
117 SCIENTIST
110 118 SET SSN = "000000001" SET SSN = "000000001"
111 119 WHERE Name = "Claire"; WHERE Name = "Claire";
112 */
120 */
113 121 -- ERROR 1062 (23000) at line 106: Duplicate entry '1' for -- ERROR 1062 (23000) at line 106: Duplicate entry '1' for
122 -- key 'PRIMARY'
114 123 ROLLBACK; ROLLBACK;
115 124
116 125 START TRANSACTION; START TRANSACTION;
 
... ... FROM FUNDS;
137 140 ROLLBACK; ROLLBACK;
138 141
139 142 START TRANSACTION; START TRANSACTION;
143
144
140 145 /* /*
141 146 DELETE FROM FUNDINGAGENCY DELETE FROM FUNDINGAGENCY
142 147 WHERE Name = "French-American Cultural Exchange"; WHERE Name = "French-American Cultural Exchange";
143 */
148 */
144 149 -- ERROR 1451 (23000): Cannot delete or update a parent row: -- ERROR 1451 (23000): Cannot delete or update a parent row:
150 -- a foreign key constraint fails
151 -- (`HW_SCIENTIFIC_RESEARCH`.`FUNDS`, CONSTRAINT
152 -- `FUNDS_ibfk_1` FOREIGN KEY (`Agency`) REFERENCES
153 -- `FUNDINGAGENCY` (`Name`) ON UPDATE CASCADE)
145 154 ROLLBACK; ROLLBACK;
146 155
147 156 -- List the name of the funding agencies created after 2000 -- List the name of the funding agencies created after 2000
157 -- ("French-American Cultural Exchange")
148 158 SELECT Name SELECT Name
149 159 FROM FUNDINGAGENCY FROM FUNDINGAGENCY
150 160 WHERE Creation >= 2000; WHERE Creation >= 2000;
151 161
152 162 -- List the code of the projects that contains the word -- List the code of the projects that contains the word
163 -- "Airplanes" ("AA", "BA")
153 164 SELECT CODE SELECT CODE
154 165 FROM PROJECT FROM PROJECT
155 166 WHERE Name LIKE ("%Airplanes%"); WHERE Name LIKE ("%Airplanes%");
156 167
157 168 -- List the number of hours scientists contributed to the -- List the number of hours scientists contributed to the
169 -- project "AA" (18)
158 170 SELECT SUM(Hours) SELECT SUM(Hours)
159 171 FROM CONTRIBUTESTO FROM CONTRIBUTESTO
160 172 WHERE Project = "AA"; WHERE Project = "AA";
161 173
162 174 -- List the code of the projects to which the scientist named -- List the code of the projects to which the scientist named
175 -- Sabine contributed ("AA", "BB")
163 176 SELECT Project SELECT Project
164 177 FROM CONTRIBUTESTO, FROM CONTRIBUTESTO,
165 178 SCIENTIST SCIENTIST
 
... ... WHERE SCIENTIST.Name = "Sabine"
175 180 AND SCIENTIST.SSN = CONTRIBUTESTO.Scientist; AND SCIENTIST.SSN = CONTRIBUTESTO.Scientist;
176 181
177 182 -- Give the name of the projects who benefited from federal -- Give the name of the projects who benefited from federal
183 -- funds ("Advancing Airplanes")
178 184 SELECT PROJECT.Name SELECT PROJECT.Name
179 185 FROM PROJECT, FROM PROJECT,
180 186 FUNDS, FUNDS,
 
... ... WHERE FUNDINGAGENCY.Type = "Federal"
185 190 AND FUNDS.Project = PROJECT.Code; AND FUNDS.Project = PROJECT.Code;
186 191
187 192 -- Give the name of the scientist who contributed to the same -- Give the name of the scientist who contributed to the same
193 -- project as Mike ("Sabine", "James")
188 194 SELECT DISTINCT (Fellow.Name) AS "Mike's fellow" SELECT DISTINCT (Fellow.Name) AS "Mike's fellow"
189 195 FROM SCIENTIST AS Mike, FROM SCIENTIST AS Mike,
190 196 SCIENTIST AS Fellow, SCIENTIST AS Fellow,
 
... ... WHERE Mike.Name = "Mike"
198 203 AND NOT Fellow.Name = "Mike"; AND NOT Fellow.Name = "Mike";
199 204
200 205 -- List the name of the projects that are not funded by an -- List the name of the projects that are not funded by an
206 -- agency ("Better Airplanes", "Better Buildings")
201 207 SELECT DISTINCT (PROJECT.Name) SELECT DISTINCT (PROJECT.Name)
202 208 FROM PROJECT, FROM PROJECT,
203 209 FUNDS FUNDS
 
... ... WHERE NOT PROJECT.Code IN (
207 212 FROM FUNDS); FROM FUNDS);
208 213
209 214 -- Give the name of the scientist who contributed the most -- Give the name of the scientist who contributed the most
215 -- (in terms of hours) to the project named "Advancing
216 -- Airplanes" (Sabine)
210 217 SELECT SCIENTIST.Name SELECT SCIENTIST.Name
211 218 FROM SCIENTIST, FROM SCIENTIST,
212 219 CONTRIBUTESTO CONTRIBUTESTO
File notes/code/sql/HW_SocialMedia.sql changed (mode: 100644) (index 3ded51f..8743579)
... ... VALUES (
75 75 DATE "2019-03-03"); DATE "2019-03-03");
76 76
77 77 -- The first entry means that 2 subscribed to 1, not the -- The first entry means that 2 subscribed to 1, not the
78 -- other way around.
79 -- And similarly for the other entries.
78 -- other way around.
79 -- And similarly for the other entries.
80 80 INSERT INTO VIDEO INSERT INTO VIDEO
81 81 VALUES ( VALUES (
82 82 10, 10,
 
... ... VALUES (
124 124 -- start snippet solution -- start snippet solution
125 125 /* code/sql/HW_SocialMedia.sql */ /* code/sql/HW_SocialMedia.sql */
126 126 -- … the title of all the videos ("My first video!", "My -- … the title of all the videos ("My first video!", "My
127 -- second video!", "My vacations").
127 -- second video!", "My vacations").
128 128 SELECT TITLE SELECT TITLE
129 129 FROM VIDEO; FROM VIDEO;
130 130
131 131 -- … the release date of the video whose title is "My first -- … the release date of the video whose title is "My first
132 -- video!" ("2020-02-02").
132 -- video!" ("2020-02-02").
133 133 SELECT Released SELECT Released
134 134 FROM VIDEO FROM VIDEO
135 135 WHERE Title = "My first video!"; WHERE Title = "My first video!";
136 136
137 137 -- … the ID of the account(s) where the "Name" attribute -- … the ID of the account(s) where the "Name" attribute
138 -- was not given ("2").
138 -- was not given ("2").
139 139 SELECT ID SELECT ID
140 140 FROM ACCOUNT FROM ACCOUNT
141 141 WHERE Name IS NULL; WHERE Name IS NULL;
142 142
143 143 -- … the ID of the videos whose title contains the word -- … the ID of the videos whose title contains the word
144 -- "video" ("10", "20").
144 -- "video" ("10", "20").
145 145 SELECT ID SELECT ID
146 146 FROM VIDEO FROM VIDEO
147 147 WHERE TITLE LIKE "%video%"; WHERE TITLE LIKE "%video%";
 
... ... FROM VIDEO
152 152 WHERE Title REGEXP 'video'; WHERE Title REGEXP 'video';
153 153
154 154 -- … the number of thumbs up for the video with title "My -- … the number of thumbs up for the video with title "My
155 -- vacations" ("1").
155 -- vacations" ("1").
156 156 SELECT COUNT(*) SELECT COUNT(*)
157 157 FROM THUMBS_UP, FROM THUMBS_UP,
158 158 VIDEO VIDEO
 
... ... ORDER BY Released ASC
180 180 LIMIT 1; LIMIT 1;
181 181
182 182 -- … the names of the accounts who gave a thumbs up to the -- … the names of the accounts who gave a thumbs up to the
183 -- video with id 30 ("Bob Ross").
183 -- video with id 30 ("Bob Ross").
184 184 SELECT Name SELECT Name
185 185 FROM ACCOUNT, FROM ACCOUNT,
186 186 THUMBS_UP THUMBS_UP
 
... ... WHERE THUMBS_UP.Video = 30
188 188 AND THUMBS_UP.Account = ACCOUNT.ID; AND THUMBS_UP.Account = ACCOUNT.ID;
189 189
190 190 -- … the ID of the account with the greatest number of -- … the ID of the account with the greatest number of
191 -- subscribers ("2").
191 -- subscribers ("2").
192 192 SELECT Subscribed SELECT Subscribed
193 193 FROM SUBSCRIBE FROM SUBSCRIBE
194 194 GROUP BY Subscribed GROUP BY Subscribed
File notes/code/sql/HW_Storm.sql changed (mode: 100644) (index 866b642..ab28c40)
... ... VALUES (
36 36 "2017-08-17"); "2017-08-17");
37 37
38 38 -- In the following, the entry gets created, but date is -- In the following, the entry gets created, but date is
39 -- "corrected" to "2017-17-08"!
40 -- INSERT INTO STORM
41 -- VALUES ("Dummy", "Hurricane", 120,
42 -- The error message returned is
43 -- ERROR 1292 (22007) at line 34: Incorrect date
44 -- "2017-17-08" for column
45 -- at
46 -- row 1
47 -- In the following, we explicitely use "DATE",
48 -- the date is incorrect, nothing gets inserted.
49 -- INSERT INTO STORM
50 -- VALUES ("Dummy2", "Hurricane", 120, DATE
51 -- "2017-17-08");
52 -- ERROR 1525 (HY000) at line 40: Incorrect DATE
53 -- "2017-17-08"
54 -- The next one sets NULL for DATE.
39 -- "corrected" to "2017-17-08"!
40 -- INSERT INTO STORM
41 -- VALUES ("Dummy", "Hurricane", 120,
42 -- "2017-17-08");
43 -- The error message returned is
44 -- ERROR 1292 (22007) at line 34: Incorrect date
45 -- value:
46 -- "2017-17-08" for column
47 -- `HW_STORM`.`STORM`.`Creation`
48 -- at
49 -- row 1
50 -- In the following, we explicitely use "DATE",
51 -- and
52 -- since
53 -- the date is incorrect, nothing gets inserted.
54 -- INSERT INTO STORM
55 -- VALUES ("Dummy2", "Hurricane", 120, DATE
56 -- "2017-17-08");
57 -- ERROR 1525 (HY000) at line 40: Incorrect DATE
58 -- value:
59 -- "2017-17-08"
60 -- The next one sets NULL for DATE.
55 61 INSERT INTO STORM INSERT INTO STORM
56 62 VALUES ( VALUES (
57 63 "Irma", "Irma",
 
... ... VALUES (
86 86 NULL); NULL);
87 87
88 88 -- This instruction is not using the primary key, is that a -- This instruction is not using the primary key, is that a
89 -- problem?
89 -- problem?
90 90 UPDATE UPDATE
91 91 STATE STATE
92 92 SET Affected_by = "Harvey" SET Affected_by = "Harvey"
File notes/code/sql/HW_TriggerExample.sql changed (mode: 100644) (index f4cd7bb..62f9ec9)
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 -- DROP TRIGGER IF EXISTS
6 -- HW_TriggerExample.NUMBER_OF_STUDENT_INC;
7 -- DROP TRIGGER IF EXISTS
8 -- HW_TriggerExample.NUMBER_OF_STUDENT_DEC;
9 9 CREATE SCHEMA HW_TriggerExample; CREATE SCHEMA HW_TriggerExample;
10 10
11 11 USE HW_TriggerExample; USE HW_TriggerExample;
 
... ... CREATE TRIGGER STUDENT_AVERAGE
83 83 WHERE STUDENT.Login = NEW.Student; WHERE STUDENT.Login = NEW.Student;
84 84
85 85 -- The "NEW" keyword here refers to the "new" entry -- The "NEW" keyword here refers to the "new" entry
86 -- that is being inserted by the INSERT statement
87 -- triggering
88 -- the trigger.
89 -- end snippet trigger-3
86 -- that is being inserted by the INSERT
87 -- statement
88 -- triggering
89 -- the trigger.
90 -- end snippet trigger-3
90 91 INSERT INTO GRADE INSERT INTO GRADE
91 92 VALUES ( VALUES (
92 93 "A", "A",
 
... ... SELECT *
112 113 FROM STUDENT; FROM STUDENT;
113 114
114 115 -- Tada, all the averages have been computed! -- Tada, all the averages have been computed!
115 -- Note also that the student "C" does not have an
116 -- average!
116 -- Note also that the student "C" does not have
117 -- an
118 -- average!
File notes/code/sql/HW_Work.sql changed (mode: 100644) (index e750737..af49feb)
... ... VALUES (
100 100 So, "Successful insertion". So, "Successful insertion".
101 101 */ */
102 102 -- The following statement raises an error. -- The following statement raises an error.
103 -- INSERT INTO AUTHOR
104 -- VALUES ("Mary B.", "mb@fai.fr", NULL);
103 -- INSERT INTO AUTHOR
104 -- VALUES ("Mary B.", "mb@fai.fr", NULL);
105 105 /* /*
106 106 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
107 107 So, "Other kind of error". So, "Other kind of error".
108 108 */ */
109 109 -- The following statement raises an error. -- The following statement raises an error.
110 -- INSERT INTO WORK
111 -- VALUES ("My Life", "Claude A.");
110 -- INSERT INTO WORK
111 -- VALUES ("My Life", "Claude A.");
112 112 /* /*
113 113 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
114 114 (`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`)
 
... ... VALUES (
128 128 So, "Successful insertion". So, "Successful insertion".
129 129 */ */
130 130 -- The following statement raises an error. -- The following statement raises an error.
131 -- INSERT INTO AUTHOR
132 -- VALUES ("Virginia W.", "alt@isp.net");
131 -- INSERT INTO AUTHOR
132 -- VALUES ("Virginia W.", "alt@isp.net");
133 133 /* /*
134 134 ERROR 1062 (23000): Duplicate entry 'Virginia W.' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry 'Virginia W.' for key 'PRIMARY'
135 135 So, "Entity integrity constraint". So, "Entity integrity constraint".
 
... ... WHERE Title = "What to eat";
175 175 Does not change any row. Does not change any row.
176 176 */ */
177 177 -- The following statement raises an error. -- The following statement raises an error.
178 -- DELETE FROM AUTHOR
179 -- WHERE Name = "Virginia W.";
178 -- DELETE FROM AUTHOR
179 -- WHERE Name = "Virginia W.";
180 180 /* /*
181 181 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
182 182 (`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";
185 185 ROLLBACK; ROLLBACK;
186 186
187 187 -- We go back to the previous state. -- We go back to the previous state.
188 -- You can now assume that there is more data than
189 -- we
190 -- inserted, if that helps you. Write a command
191 -- selects
192 -- …
193 -- We insert some dummy values for this next part.
188 -- You can now assume that there is more data
189 -- than
190 -- what
191 -- we
192 -- inserted, if that helps you. Write a command
193 -- that
194 -- selects
195 -- …
196 -- We insert some dummy values for this next
197 -- part.
194 198 INSERT INTO WORK INSERT INTO WORK
195 199 VALUES ( VALUES (
196 200 "My Life", "My Life",
 
... ... SELECT Price
230 232 FROM EBOOK; FROM EBOOK;
231 233
232 234 -- … the (distinct) names of the authors who have authored -- … the (distinct) names of the authors who have authored
233 -- a piece of work.
235 -- a piece of work.
234 236 SELECT DISTINCT Author SELECT DISTINCT Author
235 237 FROM WORK; FROM WORK;
236 238
 
... ... SELECT MAX(Price)
256 258 FROM BOOK; FROM BOOK;
257 259
258 260 -- … the number of pieces of work written by the author -- … the number of pieces of work written by the author
259 -- whose name is “Virginia W.”.
261 -- whose name is “Virginia W.”.
260 262 SELECT COUNT(*) SELECT COUNT(*)
261 263 FROM WORK FROM WORK
262 264 WHERE WORK.Author = "Virginia W."; WHERE WORK.Author = "Virginia W.";
263 265
264 266 -- … the email of the author who wrote the piece of work -- … the email of the author who wrote the piece of work
265 -- called “My Life”.
267 -- called “My Life”.
266 268 SELECT Email SELECT Email
267 269 FROM AUTHOR, FROM AUTHOR,
268 270 WORK WORK
 
... ... WHERE WORK.Title = "My Life"
270 272 AND WORK.Author = AUTHOR.Name; AND WORK.Author = AUTHOR.Name;
271 273
272 274 -- the isbn(s) of the book containing a work written by the -- the isbn(s) of the book containing a work written by the
273 -- author whose email is "vw@isp.net".
275 -- author whose email is "vw@isp.net".
274 276 SELECT ISBN SELECT ISBN
275 277 FROM BOOK, FROM BOOK,
276 278 WORK, WORK,
 
... ... WHERE
298 300 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.
299 301 */ */
300 302 -- Write one or multiple commands that would delete the work -- Write one or multiple commands that would delete the work
301 -- whose title is “My Life”, as well as all of
302 -- books
303 -- and ebooks versions of it.
304 -- The following statement raises an error.
305 -- DELETE FROM WORK
306 -- WHERE Title = "My Life";
303 -- whose title is “My Life”, as well as all
304 -- of
305 -- the
306 -- books
307 -- and ebooks versions of it.
308 -- The following statement raises an error.
309 -- DELETE FROM WORK
310 -- WHERE Title = "My Life";
307 311 /* /*
308 312 Fails Fails
309 313 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
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