Initial Commit

This commit is contained in:
2022-10-07 00:48:09 -03:00
commit 5f5056d65a
186 changed files with 2500 additions and 0 deletions

10
Labs/Lab6/1.sql Normal file
View File

@ -0,0 +1,10 @@
CREATE TABLE Courses
(
courseID INT AUTO_INCREMENT,
courseNum VARCHAR(10),
courseName VARCHAR(40),
courseDescription VARCHAR(80),
creditHours FLOAT DEFAULT 3.0,
CHECK (creditHours BETWEEN 0.0 AND 6.0),
PRIMARY KEY(courseID)
);

3
Labs/Lab6/10.sql Normal file
View File

@ -0,0 +1,3 @@
UPDATE Courses
SET approvedDate = ("2020-7-8")
where courseID = 1;

4
Labs/Lab6/11.sql Normal file
View File

@ -0,0 +1,4 @@
select studentName, courseName, courseDescription, creditHours, letterGrade
from Students
natural join Enrollments
natural join Courses;

2
Labs/Lab6/12.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO Students(studentName, email, gpa, dateOfBirth)
VALUES ('Isaac Shoebottom', 'ir.shoebottom@gmail.com', 3.5, "2002-08-07");

2
Labs/Lab6/13.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO Enrollments(studentID, courseID, letterGrade)
VALUES(1, 1, 'A+');

2
Labs/Lab6/14.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO Enrollments(studentID, courseID, letterGrade)
VALUES(1, 2, 'B');

11
Labs/Lab6/2.sql Normal file
View File

@ -0,0 +1,11 @@
CREATE TABLE Students
(
studentID INT AUTO_INCREMENT,
studentName VARCHAR(30) NOT NULL,
email VARCHAR(40),
gpa FLOAT DEFAULT 0.0,
PRIMARY KEY (studentID),
CONSTRAINT CHECK_GPA
CHECK (gpa BETWEEN 0 and 4.3)
);
ALTER TABLE Students ADD dateOfBirth DATETIME;

11
Labs/Lab6/3.sql Normal file
View File

@ -0,0 +1,11 @@
CREATE TABLE Enrollments
(
studentID INT,
courseID INT,
letterGrade CHAR(2),
PRIMARY KEY(studentID, courseID),
FOREIGN KEY(studentID)
REFERENCES Students(studentID)
ON DELETE NO ACTION
ON UPDATE CASCADE
);

5
Labs/Lab6/4.sql Normal file
View File

@ -0,0 +1,5 @@
ALTER TABLE Enrollments
ADD FOREIGN KEY(courseID)
REFERENCES Courses(courseID)
ON DELETE NO ACTION
ON UPDATE CASCADE;

5
Labs/Lab6/5.sql Normal file
View File

@ -0,0 +1,5 @@
ALTER TABLE Enrollments
ADD FOREIGN KEY(studentID)
REFERENCES Students(studentID)
ON DELETE NO ACTION
ON UPDATE CASCADE;

2
Labs/Lab6/7.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO Courses(courseNum, courseName, courseDescription, creditHours)
VALUES ('CS1103', 'Data & Information Management', 'Introduction to Databases', 7);

2
Labs/Lab6/8.sql Normal file
View File

@ -0,0 +1,2 @@
INSERT INTO Courses(courseNum, courseName, courseDescription, creditHours)
VALUES ('CS1303', 'Discrete Structures', 'Computer Science but it\'s math actually', 4);

1
Labs/Lab6/9.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE Courses ADD approvedDate DATETIME;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,253 @@
Script started on Thu Mar 11 17:15:35 2021
]0;ishoebot@gc112m01:~[ishoebot@gc112m01 ~]$ exitlsdwa783987473829y2benjknbfdskbncxknbczxdwadwannd``eexitmysql -u ishoebot -p -h cs1103.cs.unb.ca
Enter password:
(BWelcome to the MariaDB monitor. Commands end with ; or \g.
(B(BYour MariaDB connection id is 590
Server version: 5.5.65-MariaDB MariaDB Server
(B(BCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
(B(BType 'help;' or '\h' for help. Type '\c' to clear the current input statement.
(B[?1034hMariaDB [(none)]> uys  se ishoebot
(BDatabase changed
(BMariaDB [ishoebot]> CREATE TABLE Students
-> (
-> studentID INT AUTO_INCREMENT,
-> studentName VARCHAR(30) NOT NULL,
-> email VARCHAR(40),
-> gpa FLOAT DEFAULT 0.0,
IMAR -> PRIMARY KEY (studentID)
-> CONSTRAINT CHECK_GPA
->  CHECK (gpa BETWEEN 0 and 4.3)
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CONSTRAINT CHECK_GPA
CHECK (gpa BETWEEN 0 and 4.3)
)' at line 8
(B(BMariaDB [ishoebot]> CREATE TABLE Students
-> (
-> studentID INT AUTO_INCREMENT,
-> studentName VARCHAR(30) NOT NULL,
-> email VARCHAR(40),
-> gpa FLOAT DEFAULT 0.0,
-> PRIMARY KEY (studentID),
-> CONSTRAINT CHECK_GPA
->  CHECK (gpa BETWEEN 0 and 4.3)
-> );
(BQuery OK, 0 rows affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Students ADD dateOfBirth DATETIME;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 0 rows affected (0.01 sec)
(B(BRecords: 0 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> CREATE TABLE Enrollments
-> (
-> studentID INT,
-> courseID INT,
-> letterGrade CHAR(2),
-> PRIMARY KEY(studentID, courseID),
-> FOREIGN KEY(studentID)
-> REFERENCES Students(studentID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE
-> );
(BQuery OK, 0 rows affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> CREATE TABLE Courses
-> (
-> courseID INT AUTO_INCREMENT,
-> courseNum VARCHAR(10),
-> courseName VARCHAR(40),
-> courseDescription VARCHAR(80),
creditHours FL -> creditHours FLOAT DEFAULT 3.0,
-> CHECK (creditHours BETWEEN 0.0 AND 6.0)
-> PRIMARY KEY(courseID)
-> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
 -> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'PRIMARY KEY(courseID)
)' at line 9
(B(BMariaDB [ishoebot]> CREATE TABLE Courses
-> (
-> courseID INT AUTO_INCREMENT,
-> courseNum VARCHAR(10),
-> courseName VARCHAR(40),
-> courseDescription VARCHAR(80),
-> creditHours FLOAT DEFAULT 3.0,
-> CHECK (creditHours BETWEEN 0.0 AND 6.0),
EY(courseID -> PRIMARY KEY(courseID)
-> );
(BQuery OK, 0 rows affected (0.01 sec)
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> (
-> FOREIGN KEY(courseID)
FERE -> REFERENCES Courses(courseID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(
FOREIGN KEY(courseID)
REFERENCES Courses(courseID)
ON DELETE NO ACTION
' at line 2
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> (
-> ADD FOREIGN KEY(courseID)
-> REFERENCES Courses(courseID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE
-> );
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(
ADD FOREIGN KEY(courseID)
REFERENCES Courses(courseID)
ON DELETE NO ACTI' at line 2
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> FOREIGN KEY(courseID)
-> REFERENCES Courses(courseID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FOREIGN KEY(courseID)
REFERENCES Courses(courseID)
ON DELETE NO ACTION
' at line 2
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> ADD FOREIGN KEY(courseID)
-> REFERENCES Courses(courseID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 0 rows affected (0.01 sec)
(B(BRecords: 0 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> ADD FOREIGN KEY(StudentID)
-> REFERENCES Students(StudentID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 0 rows affected (0.01 sec)
(B(BRecords: 0 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> ADD FOREIGN KEY(studentID)
-> REFERENCES Students(studentID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 0 rows affected (0.01 sec)
(B(BRecords: 0 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> ALTER TABLE EN nrollments DROP CONSTRAINT ENrollm      nrollments_ibfk_4
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CONSTRAINT Enrollments_ibfk_4' at line 1
(B(BMariaDB [ishoebot]> ;ALTER TABLE Enrollments DROP CONSTRAINT Enrollments_ibfk_4                  studentID;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CONSTRAINT studentID' at line 1
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments DROP CONSTRAINT studentID;
MariaDB [ishoebot]> ;ALTER TABLE Enrollments DROP CONSTRAINT Enrollments_ibfk_4 4l ;s  DROP CONSTRAINT[1@I[1@N[1@D[1@E[1@X Enrollments_ibfk_4;
ERROR 1091 (42000): Can't DROP 'Enrollments_ibfk_4'; check that column/key exists
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments DROP INDEX Enrollments_ibfk_4;                   St  studentID;
ERROR 1091 (42000): Can't DROP 'studentID'; check that column/key exists
(B(BMariaDB [ishoebot]> ALTER TABLE Enrollments DROP INDEX studentID;                constraint                                       slect    elect studentID from Enrollments where                                         atler      lter table student       Enrollments drop coluy    olumn studentID cascade constraints
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'constraints' at line 1
(B(BMariaDB [ishoebot]> ;alter table Enrollments drop column studentID cascade constraintsmn stttn[1@i[1@n[1@d[1@e[1@x
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'cascade constraints' at line 1
(B(BMariaDB [ishoebot]> ;alter table Enrollments drop index studentID cascade constraints
MariaDB [ishoebot]> ;alter table Enrollments drop column studentID cascade constraintss           indexl ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'index' at line 1
(B(BMariaDB [ishoebot]> alter table Enrollments drop column studentID cascade index;
MariaDB [ishoebot]> ;alter table Enrollments drop index studentID cascade constraintsex[1@s[1@t[1@u[1@d studentID cascade constraints;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'constraints' at line 1
(B(BMariaDB [ishoebot]> drop table Enrollments
-> ;
(BQuery OK, 0 rows affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> CREATE TABLE Enrollments
-> (
-> studentID INT,
-> courseID INT,
-> letterGrade CHAR(2),
-> PRIMARY KEY(studentID, courseID),
-> FOREIGN KEY(studentID)
-> REFERENCES Students(studentID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE
-> );
(BQuery OK, 0 rows affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Enrollments
-> ADD FOREIGN KEY(courseID)
-> REFERENCES Courses(courseID)
-> ON DELETE NO ACTION
-> ON UPDATE CASCADE;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 0 rows affected (0.01 sec)
(B(BRecords: 0 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> INSERT INTO Courses(courseNum, courseName, courseDescription, creditHours)
Data & Inform -> VALUES ('CS1103', 'Data & Information Management', 'Introduction to Databases', 7);
(BQuery OK, 1 row affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> select * from Courses;
+----------+-----------+-------------------------------+---------------------------+-------------+
| courseID | courseNum | courseName | courseDescription | creditHours |
+----------+-----------+-------------------------------+---------------------------+-------------+
| 1 | CS1103 | Data & Information Management | Introduction to Databases | 7 |
+----------+-----------+-------------------------------+---------------------------+-------------+
(B1 row in set (0.00 sec)
(B(B
(BMariaDB [ishoebot]> INSERT INTO Courses(courseNum, courseName, courseDescription, creditHours)
-> VALUES ('CS1303', 'Discrete Structures', 'Computer Science but it\'s math actually', 4);
(BQuery OK, 1 row affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> ALTER TABLE Courses ADD approvedDate DATETIME;
Stage: 2 of 2 'Enabling keys' 0% of stage done
(BQuery OK, 2 rows affected (0.01 sec)
(B(BRecords: 2 Duplicates: 0 Warnings: 0
(B(B
(BMariaDB [ishoebot]> UPDATE Courses
rovedDate = ("2020-7- -> SET approvedDate = ("2020-7-8")
-> where courseID = 1;
(BQuery OK, 1 row affected (0.00 sec)
(B(BRows matched: 1 Changed: 1 Warnings: 0
(B(B
(BMariaDB [ishoebot]> select studentName, courseName, letterGrade
-> from Students
-> natural join Enrollments
-> natural join Courses;
(BEmpty set (0.00 sec)
(B(B
(BMariaDB [ishoebot]> INSERT INTO Students(studentName, email, gpa, dateOfBirth)
-> VALUES ('Isaac Shoebottom', 'ir.shoebottom@gmail.com', 3.5, "2002-08-07");
(BQuery OK, 1 row affected (0.00 sec)
(B(B
(BMariaDB [ishoebot]> INSERT INTO Enrollments(studentID, courseID, letterGrade)
-> VALUES(1, 1, '85');
(BQuery OK, 1 row affected (0.01 sec)
(B(B
(BMariaDB [ishoebot]> INSERT INTO Enrollments(studentID, courseID, letterGrade)
-> VALUES(1, 2, '95');
(BQuery OK, 1 row affected (0.01 sec)
(B(B
(BMariaDB [ishoebot]> select studentName, courseName, letterGrade
-> from Students
-> natural join Enrollments