List of commits:
Subject Hash Author Date (UTC)
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
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
Commit 0948cee47ed78dc115fd69c7bcf96a312dd3162f - Added solution to first problem.
Author: aubert@math.cnrs.fr
Author date (UTC): 2020-09-18 21:43
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2020-09-18 21:43
Parent(s): 7ad20b3c0025a4de3fa00729de570c6fe9176773
Signer:
Signing key:
Signing status: N
Tree: a4984d0577096ed4d0625f2dedcef95393beaf7b
File Lines added Lines deleted
notes/code/sql/HW_ScientificResearch.sql 123 0
File notes/code/sql/HW_ScientificResearch.sql added (mode: 100644) (index 0000000..408fa6e)
1 /* code/sql/HW_SCIENTIFIC_RESEARCH.sql */
2
3
4 DROP SCHEMA IF EXISTS HW_SCIENTIFIC_RESEARCH;
5 CREATE SCHEMA HW_SCIENTIFIC_RESEARCH;
6 USE HW_SCIENTIFIC_RESEARCH;
7
8
9 CREATE TABLE SCIENTIST (
10 SSN INT PRIMARY KEY,
11 Name VARCHAR(30) NOT NULL
12 );
13
14 CREATE TABLE PROJECT (
15 Code CHAR(4) PRIMARY KEY,
16 Name VARCHAR(150) NOT NULL
17 );
18
19 CREATE TABLE CONTRIBUTESTO (
20 Scientist INT,
21 Project CHAR(4),
22 Hours INT NOT NULL CHECK (Hours > 0),
23 PRIMARY KEY (Scientist, Project),
24 FOREIGN KEY (Scientist) REFERENCES SCIENTIST(SSN),
25 FOREIGN KEY (Project) REFERENCES PROJECT(Code)
26 ON DELETE CASCADE
27 ON UPDATE CASCADE
28 );
29
30 CREATE TABLE FUNDINGAGENCY (
31 Name VARCHAR(150) PRIMARY KEY,
32 Type ENUM("State", "Federal", "Foundation"),
33 Creation YEAR
34 );
35
36 CREATE TABLE FUNDS (
37 Agency VARCHAR(150),
38 Project CHAR(4),
39 Amount DECIMAL(12, 2),
40 FOREIGN KEY (Agency) REFERENCES FUNDINGAGENCY(Name)
41 ON UPDATE CASCADE
42 ON DELETE RESTRICT,
43 FOREIGN KEY (Project) REFERENCES PROJECT(Code)
44 );
45
46
47 INSERT INTO SCIENTIST VALUES
48 ("000000000", "Mike"), -- S.1
49 ("000000001", "Sabine"), -- S.2
50 ("000000002", "James"), -- S.3
51 ("000000003", "Emily"), -- S.4
52 ("000000004", "Claire"); -- S.5
53
54 INSERT INTO PROJECT VALUES
55 ("AA", "Advancing Airplanes"), -- P.1
56 ("BA", "Better Airplanes"), -- P.2
57 ("BB", "Better Buildings"), -- P.3
58 ("CC", "Creative Creation"); -- P.4
59
60 INSERT INTO CONTRIBUTESTO VALUES
61 ("000000001", "AA", 12), -- C.1
62 ("000000001", "BB", 10), -- C.2
63 ("000000002", "AA", 5), -- C.3
64 ("000000003", "BA", 3), -- C.4
65 ("000000000", "BB", 1), -- C.5
66 ("000000000", "AA", 1); -- C.6
67
68 INSERT INTO FUNDINGAGENCY VALUES
69 ("National Science Foundation", "Federal", 1950), -- FA.1
70 ("French-American Cultural Exchange", "Foundation", 2017); -- FA.2
71
72 INSERT INTO FUNDS VALUES
73 ("National Science Foundation", "AA", 100000), -- F.1
74 ("French-American Cultural Exchange", "CC", 10000); -- F.2
75
76 -- List the name of the funding agencies created after 2000 ("French-American Cultural Exchange")
77 SELECT Name FROM FUNDINGAGENCY WHERE Creation >= 2000;
78
79 -- List the code of the projects that contains the word "Airplanes" ("AA", "BA")
80 SELECT CODE FROM PROJECT WHERE Name LIKE ("%Airplanes%");
81
82 -- List the number of hours scientists contributed to the project "AA" (18)
83 SELECT SUM(Hours) FROM CONTRIBUTESTO WHERE Project = "AA";
84
85 -- List the code of the projects to which the scientist named Sabine contributed ("AA", "BB")
86 SELECT Project FROM CONTRIBUTESTO, SCIENTIST WHERE SCIENTIST.Name = "Sabine" AND SCIENTIST.SSN = CONTRIBUTESTO.Scientist;
87
88 -- Give the name of the projects who benefited from federal funds ("Advancing Airplanes")
89 SELECT PROJECT.Name FROM PROJECT, FUNDS, FUNDINGAGENCY WHERE FUNDINGAGENCY.Type = "Federal" AND FUNDINGAGENCY.Name = FUNDS.Agency AND FUNDS.Project = PROJECT.Code;
90
91 -- Give the name of the scientist who contributed to the same project as Mike ("Sabine", "James")
92 SELECT DISTINCT(Fellow.Name) AS "Mike's fellow" FROM SCIENTIST AS Mike, SCIENTIST AS Fellow, CONTRIBUTESTO AS A, CONTRIBUTESTO AS B WHERE Mike.Name = "Mike" AND Mike.SSN = A.Scientist AND A.Project = B.Project AND B.Scientist = Fellow.SSN AND NOT Fellow.Name = "Mike";
93
94 -- List the name of the projects that are not funded by an agency ("Better Airplanes", "Better Buildings")
95 SELECT DISTINCT(PROJECT.Name) FROM PROJECT, FUNDS WHERE NOT PROJECT.Code IN (SELECT FUNDS.Project FROM FUNDS);
96
97 -- Give the name of the scientist who contributed the most (in terms of hours) to the project named "Advancing Airplanes" (Sabine)
98 SELECT SCIENTIST.Name FROM SCIENTIST, CONTRIBUTESTO WHERE CONTRIBUTESTO.Hours >= (SELECT MAX(Hours) FROM CONTRIBUTESTO, PROJECT WHERE PROJECT.Name = "Advancing Airplanes" AND PROJECT.Code = CONTRIBUTESTO.Project) AND CONTRIBUTESTO.Scientist = SCIENTIST.SSN;
99
100
101 -- List the rows affected (updated or deleted) by the following commands.
102 -- If no rows are affected because the command would would violate the entity integrity constraint, the referential integrity constraint, or if there would be some other kind of error, please indicate it.
103
104
105 START TRANSACTION;
106 UPDATE SCIENTIST SET SSN = "000000001" WHERE Name = "Claire";
107 -- ERROR 1062 (23000) at line 106: Duplicate entry '1' for key 'PRIMARY'
108 ROLLBACK;
109
110
111 START TRANSACTION;
112 UPDATE FUNDINGAGENCY SET Name = "NSF" WHERE Name = "National Science Foundation";
113 SELECT * FROM FUNDINGAGENCY; -- FA. 1
114 SELECT * FROM FUNDS; -- F.1
115 ROLLBACK;
116
117
118 START TRANSACTION;
119 DELETE FROM FUNDINGAGENCY WHERE Name = "French-American Cultural Exchange";
120 -- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`HW_SCIENTIFIC_RESEARCH`.`FUNDS`, CONSTRAINT `FUNDS_ibfk_1` FOREIGN KEY (`Agency`) REFERENCES `FUNDINGAGENCY` (`Name`) ON UPDATE CASCADE)
121 ROLLBACK;
122
123
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