Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.13 MySQL Community Server - GPL Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | toyu | | universal | +--------------------+ 11 rows in set (0.05 sec) mysql> use toyu; Database changed mysql> show tables; +----------------+ | Tables_in_toyu | +----------------+ | class | | course | | department | | enroll | | faculty | | grade | | school | | student | +----------------+ 8 rows in set (0.05 sec) mysql> ? For information about MySQL products and services, visit: http://www.mysql.com/ For developer information, including the MySQL Reference Manual, visit: http://dev.mysql.com/ To buy MySQL Enterprise support, training, or other products, visit: https://shop.mysql.com/ List of all MySQL commands: Note that all text commands must be first on line and end with ';' ? (\?) Synonym for `help'. clear (\c) Clear the current input statement. connect (\r) Reconnect to the server. Optional arguments are db and host. delimiter (\d) Set statement delimiter. ego (\G) Send command to mysql server, display result vertically. exit (\q) Exit mysql. Same as quit. go (\g) Send command to mysql server. help (\h) Display this help. notee (\t) Don't write into outfile. print (\p) Print current command. prompt (\R) Change your mysql prompt. quit (\q) Quit mysql. rehash (\#) Rebuild completion hash. source (\.) Execute an SQL script file. Takes a file name as an argument. status (\s) Get status information from the server. tee (\T) Set outfile [to_outfile]. Append everything into given outfile. use (\u) Use another database. Takes database name as argument. charset (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets. warnings (\W) Show warnings after every statement. nowarning (\w) Don't show warnings after every statement. resetconnection(\x) Clean session context. For server side help, type 'help contents' mysql> SELECT * FROM Student; +--------+-----------+---------+-------+-------+---------+---------+ | stuId | fname | lname | major | minor | credits | advisor | +--------+-----------+---------+-------+-------+---------+---------+ | 100000 | Tony | Hawk | CSCI | CINF | 40 | 1011 | | 100001 | Mary | Hawk | CSCI | CINF | 35 | 1011 | | 100002 | David | Hawk | CSCI | ITEC | 66 | 1011 | | 100003 | Catherine | Lim | ITEC | CINF | 20 | 1017 | | 100004 | Larry | Johnson | ITEC | NULL | 66 | 1017 | | 100005 | Linda | Johnson | CINF | ENGL | 13 | 1015 | | 100006 | Lillian | Johnson | CINF | ITEC | 18 | 1015 | | 100007 | Ben | Zico | NULL | NULL | 16 | NULL | | 100008 | Bill | Ching | ARTS | ENGL | 90 | 1018 | | 100009 | Linda | King | ARTS | CSCI | 125 | 1018 | +--------+-----------+---------+-------+-------+---------+---------+ 10 rows in set (0.03 sec) mysql> SELECT * FROM toyu.Student; +--------+-----------+---------+-------+-------+---------+---------+ | stuId | fname | lname | major | minor | credits | advisor | +--------+-----------+---------+-------+-------+---------+---------+ | 100000 | Tony | Hawk | CSCI | CINF | 40 | 1011 | | 100001 | Mary | Hawk | CSCI | CINF | 35 | 1011 | | 100002 | David | Hawk | CSCI | ITEC | 66 | 1011 | | 100003 | Catherine | Lim | ITEC | CINF | 20 | 1017 | | 100004 | Larry | Johnson | ITEC | NULL | 66 | 1017 | | 100005 | Linda | Johnson | CINF | ENGL | 13 | 1015 | | 100006 | Lillian | Johnson | CINF | ITEC | 18 | 1015 | | 100007 | Ben | Zico | NULL | NULL | 16 | NULL | | 100008 | Bill | Ching | ARTS | ENGL | 90 | 1018 | | 100009 | Linda | King | ARTS | CSCI | 125 | 1018 | +--------+-----------+---------+-------+-------+---------+---------+ 10 rows in set (0.00 sec) mysql> SELECT * from toyu.Student; +--------+-----------+---------+-------+-------+---------+---------+ | stuId | fname | lname | major | minor | credits | advisor | +--------+-----------+---------+-------+-------+---------+---------+ | 100000 | Tony | Hawk | CSCI | CINF | 40 | 1011 | | 100001 | Mary | Hawk | CSCI | CINF | 35 | 1011 | | 100002 | David | Hawk | CSCI | ITEC | 66 | 1011 | | 100003 | Catherine | Lim | ITEC | CINF | 20 | 1017 | | 100004 | Larry | Johnson | ITEC | NULL | 66 | 1017 | | 100005 | Linda | Johnson | CINF | ENGL | 13 | 1015 | | 100006 | Lillian | Johnson | CINF | ITEC | 18 | 1015 | | 100007 | Ben | Zico | NULL | NULL | 16 | NULL | | 100008 | Bill | Ching | ARTS | ENGL | 90 | 1018 | | 100009 | Linda | King | ARTS | CSCI | 125 | 1018 | +--------+-----------+---------+-------+-------+---------+---------+ 10 rows in set (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | toyu | | universal | +--------------------+ 11 rows in set (0.00 sec) mysql> show tables; +----------------+ | Tables_in_toyu | +----------------+ | class | | course | | department | | enroll | | faculty | | grade | | school | | student | +----------------+ 8 rows in set (0.00 sec) mysql> DROP SCHEMA IF EXISTS toyu; Query OK, 8 rows affected (0.88 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | universal | +--------------------+ 10 rows in set (0.00 sec) mysql> show tables; ERROR 1046 (3D000): No database selected mysql> CREATE SCHEMA toyu; Query OK, 1 row affected (0.04 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | toyu | | universal | +--------------------+ 11 rows in set (0.03 sec) mysql> USE toyu; Database changed mysql> show tables; Empty set (0.00 sec) mysql> DROP TABLE IF EXISTS Enroll; Query OK, 0 rows affected, 1 warning (0.04 sec) mysql> DROP TABLE IF EXISTS Student; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Class; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Course; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Faculty; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Department; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS school; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Grade; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> mysql> show tables; Empty set (0.00 sec) mysql> CREATE TABLE IF NOT EXISTS grade ( -> grade VARCHAR(2), -> gradePoint DECIMAL(5,4), -> CONSTRAINT Grade_grade_pk PRIMARY KEY (grade) -> ); Query OK, 0 rows affected (0.32 sec) mysql> show tables; +----------------+ | Tables_in_toyu | +----------------+ | grade | +----------------+ 1 row in set (0.00 sec) mysql> SELECT * FROM Grade; Empty set (0.00 sec) mysql> INSERT INTO Grade VALUES -> ('A',4),('A-',3.6667),('B+',3.3333),('B',3),('B-',2.6667), -> ('C+',2.3333),('C',2),('C-',1.6667), -> ('D+',1.3333),('D',1),('D-',0.6667),('F',0), -> ('WX', NULL); Query OK, 13 rows affected (0.06 sec) Records: 13 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM Grade; +-------+------------+ | grade | gradePoint | +-------+------------+ | A | 4.0000 | | A- | 3.6667 | | B | 3.0000 | | B- | 2.6667 | | B+ | 3.3333 | | C | 2.0000 | | C- | 1.6667 | | C+ | 2.3333 | | D | 1.0000 | | D- | 0.6667 | | D+ | 1.3333 | | F | 0.0000 | | WX | NULL | +-------+------------+ 13 rows in set (0.00 sec) mysql> INSERT INTO Grade VALUES ('A', 5.3333); ERROR 1062 (23000): Duplicate entry 'A' for key 'PRIMARY' mysql> DROP SCHEMA IF EXISTS toyu; Query OK, 1 row affected (0.13 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | universal | +--------------------+ 10 rows in set (0.00 sec) mysql> -- mysql> -- mysql> -- Create a very simplified university database mysql> -- mysql> -- mysql> -- Drop tables for house-keeping if necessary mysql> -- mysql> mysql> SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; Query OK, 0 rows affected (0.00 sec) mysql> SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; Query OK, 0 rows affected (0.00 sec) mysql> SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; Query OK, 0 rows affected (0.00 sec) mysql> mysql> DROP SCHEMA IF EXISTS toyu; Query OK, 0 rows affected, 1 warning (0.04 sec) mysql> CREATE SCHEMA toyu; Query OK, 1 row affected (0.03 sec) mysql> USE toyu; Database changed mysql> mysql> DROP TABLE IF EXISTS Enroll; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Student; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Class; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Course; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Faculty; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Department; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS school; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> DROP TABLE IF EXISTS Grade; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> mysql> mysql> -- mysql> mysql> CREATE TABLE IF NOT EXISTS grade ( -> grade VARCHAR(2), -> gradePoint DECIMAL(5,4), -> CONSTRAINT Grade_grade_pk PRIMARY KEY (grade) -> ); Query OK, 0 rows affected (0.17 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS school ( -> schoolCode VARCHAR(3), -> schoolName VARCHAR(30), -> CONSTRAINT School_schoolCode_pk PRIMARY KEY (schoolCode), -> CONSTRAINT School_name_ck UNIQUE (schoolName) -> ); Query OK, 0 rows affected (0.17 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Department ( -> deptCode VARCHAR(4), -> deptName VARCHAR(30), -> schoolCode VARCHAR(3), -> numFaculty TINYINT, -> CONSTRAINT Department_deptCode_pk PRIMARY KEY (deptCode), -> CONSTRAINT Department_name_ck UNIQUE (deptName), -> CONSTRAINT Department_schoolCode_fk FOREIGN KEY (schoolCode) -> REFERENCES School(schoolCode) -> ); Query OK, 0 rows affected (0.22 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Faculty ( -> facId INT NOT NULL, -> fname VARCHAR(20) NOT NULL, -> lname VARCHAR(20) NOT NULL, -> deptCode VARCHAR(4) NOT NULL, -> `rank` VARCHAR(25), -> CONSTRAINT Faculty_facId_pk PRIMARY KEY (facId), -> CONSTRAINT Faculty_deptCode_fk FOREIGN KEY (deptCode) -> REFERENCES Department(deptCode)); Query OK, 0 rows affected (0.16 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Course ( -> courseId INT NOT NULL, -> rubric char(4) NOT NULL, -> number char(4) NOT NULL, -> name VARCHAR(80) NOT NULL, -> credits TINYINT, -> CONSTRAINT Course_courseId_pk PRIMARY KEY (courseId), -> CONSTRAINT Course_deptCode_fk FOREIGN KEY (rubric) -> REFERENCES Department(deptCode)); Query OK, 0 rows affected (0.13 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Class ( -> classId INT NOT NULL AUTO_INCREMENT, -> courseId INT NOT NULL, -> semester VARCHAR(10) NOT NULL, -> year DECIMAL(4,0) NOT NULL, -> facId INT NOT NULL, -> room VARCHAR(6), -> CONSTRAINT Class_classId_pk PRIMARY KEY (classId), -> CONSTRAINT Class_courseId_fk FOREIGN KEY (courseId) -> REFERENCES Course(courseId) ON DELETE CASCADE, -> CONSTRAINT Class_facId_fk FOREIGN KEY (facId) -> REFERENCES Faculty (facId) ON DELETE CASCADE -> ); Query OK, 0 rows affected (0.34 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Student ( -> stuId INT NOT NULL, -> fname VARCHAR(20) NOT NULL, -> lname VARCHAR(20) NOT NULL, -> major VARCHAR(4) NULL, -> minor VARCHAR(4) NULL, -> credits integer(3) DEFAULT 0, -> advisor INT NULL, -> CONSTRAINT Student_stuId_pk PRIMARY KEY(stuId), -> CONSTRAINT Student_credits_cc CHECK ((credits>=0) AND (credits < 250)), -> CONSTRAINT Student_major_fk FOREIGN KEY (major) -> REFERENCES Department(deptCode) ON DELETE CASCADE, -> CONSTRAINT Student_minor_fk FOREIGN KEY (minor) -> REFERENCES Department(deptCode) ON DELETE CASCADE, -> CONSTRAINT Student_advisor_fk FOREIGN KEY (advisor) -> REFERENCES Faculty(facId) -> ); Query OK, 0 rows affected (0.35 sec) mysql> mysql> CREATE TABLE IF NOT EXISTS Enroll( -> stuId INT NOT NULL, -> classId INT NOT NULL, -> grade VARCHAR(2), -> n_alerts INT, -> CONSTRAINT Enroll_classId_stuId_pk PRIMARY KEY (classId, stuId), -> CONSTRAINT Enroll_classNumber_fk FOREIGN KEY (classId) -> REFERENCES Class(classId) ON DELETE CASCADE, -> CONSTRAINT Enroll_stuId_fk FOREIGN KEY (stuId) -> REFERENCES Student (stuId) ON DELETE CASCADE, -> CONSTRAINT Enroll_grade_fk FOREIGN KEY (grade) -> REFERENCES Grade (grade) ON DELETE CASCADE -> ); Query OK, 0 rows affected (0.24 sec) mysql> mysql> INSERT INTO Grade VALUES -> ('A',4),('A-',3.6667),('B+',3.3333),('B',3),('B-',2.6667), -> ('C+',2.3333),('C',2),('C-',1.6667), -> ('D+',1.3333),('D',1),('D-',0.6667),('F',0), -> ('WX', NULL); Query OK, 13 rows affected (0.01 sec) Records: 13 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO school VALUES -> ('BUS','Business'),('EDU','Education'), -> ('HSH','Human Sciences and Humanities'), -> ('CSE','Science and Engineering'); Query OK, 4 rows affected (0.03 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO DEPARTMENT VALUES -> ('ACCT','Accounting','BUS',10), -> ('ARTS','Arts','HSH',5), -> ('CINF','Computer Information Systems','CSE',5), -> ('CSCI','Computer Science','CSE',12), -> ('ENGL','English','HSH',12), -> ('ITEC','Information Technology','CSE',4), -> ('MATH','Mathematics','CSE',7); Query OK, 7 rows affected (0.01 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO FACULTY VALUES -> (1011,'Paul','Smith','CSCI','Professor'), -> (1012,'Mary','Tran','CSCI','Associate Professor'), -> (1013,'David','Love','CSCI',NULL), -> (1014,'Sharon','Mannes','CSCI','Assistant Professor'), -> (1015,'Daniel','Kim','CINF','Professor'), -> (1016,'Andrew','Byre','CINF','Associate Professor'), -> (1017,'Deborah','Gump','ITEC','Professor'), -> (1018,'Art','Allister','ARTS','Assistant Professor'), -> (1019,'Benjamin','Yu','ITEC','Lecturer'), -> (1020,'Katrina','Bajaj','ENGL','Lecturer'), -> (1021,'Jorginlo','Neymar','ACCT','Assistant Professor'); Query OK, 11 rows affected (0.06 sec) Records: 11 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO COURSE VALUES -> (2000,'CSCI',3333,'Data Structures',3), -> (2001,'CSCI',4333,'Design of Database Systems',3), -> (2002,'CSCI',5333,'DBMS',3), -> (2020,'CINF',3321,'Introduction to Information Systems',3), -> (2021,'CINF',4320,'Web Application Development',3), -> (2040,'ITEC',3335,'Database Development',3), -> (2041,'ITEC',3312,'Introduction to Scripting',3), -> (2060,'ENGL',1410,'English I',4), -> (2061,'ENGL',1311,'English II',3), -> (2080,'ARTS',3311,'Hindu Arts',3), -> (2090,'ACCT',3333,'Managerial Accounting',3); Query OK, 11 rows affected (0.05 sec) Records: 11 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO CLASS VALUES -> (10000,2000,'Fall',2019,1011,'D241'), -> (10001,2001,'Fall',2019,1011,'D242'), -> (10002,2002,'Fall',2019,1012,'D136'), -> (10003,2020,'Fall',2019,1014,'D241'), -> (10004,2021,'Fall',2019,1014,'D241'), -> (10005,2040,'Fall',2019,1015,'D237'), -> (10006,2041,'Fall',2019,1019,'D217'), -> (10007,2060,'Fall',2019,1020,'B101'), -> (10008,2080,'Fall',2019,1018,'D241'), -> (11000,2000,'Spring',2020,1011,'D241'), -> (11001,2001,'Spring',2020,1013,'D242'), -> (11002,2002,'Spring',2020,1013,'D136'), -> (11003,2020,'Spring',2020,1016,'D217'), -> (11004,2061,'Spring',2020,1018,'B101'); Query OK, 14 rows affected (0.06 sec) Records: 14 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO STUDENT VALUES -> (100000,'Tony','Hawk','CSCI','CINF',40,1011), -> (100001,'Mary','Hawk','CSCI','CINF',35,1011), -> (100002,'David','Hawk','CSCI','ITEC',66,1011), -> (100003,'Catherine','Lim','ITEC','CINF',20,1017), -> (100004,'Larry','Johnson','ITEC',NULL,66,1017), -> (100005,'Linda','Johnson','CINF','ENGL',13,1015), -> (100006,'Lillian','Johnson','CINF','ITEC',18,1015), -> (100007,'Ben','Zico',NULL,NULL,16,NULL), -> (100008,'Bill','Ching','ARTS','ENGL',90,1018), -> (100009,'Linda','King','ARTS','CSCI',125,1018); Query OK, 10 rows affected (0.06 sec) Records: 10 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO ENROLL VALUES -> (100000,10000,'A',0), -> (100001,10000,NULL,NULL), -> (100002,10000,'B-',3), -> (100000,10001,'A',2), -> (100001,10001,'A-',0), -> (100000,10002,'B+',1), -> (100002,10002,'B+',2), -> (100000,10003,'C',0), -> (100002,10003,'D',4), -> (100004,10003,'A',0), -> (100005,10003,NULL,NULL), -> (100000,10004,'A-',1), -> (100004,10004,'B+',NULL), -> (100005,10004,'A-',0), -> (100006,10004,'C+',NULL), -> (100005,10005,'A-',0), -> (100006,10005,'A',NULL), -> (100005,10006,'B+',NULL), -> (100007,10007,'F',4), -> (100008,10007,'C-',0), -> (100007,10008,'A-',0), -> (100000,11001,'D',4); Query OK, 22 rows affected (0.05 sec) Records: 22 Duplicates: 0 Warnings: 0 mysql> mysql> SET SQL_MODE=@OLD_SQL_MODE; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | c4333u | | clystms | | experiment | | information_schema | | mysql | | performance_schema | | sakila | | supply | | sys | | toyu | | universal | +--------------------+ 11 rows in set (0.03 sec) mysql> use toyu; Database changed mysql> show tables; +----------------+ | Tables_in_toyu | +----------------+ | class | | course | | department | | enroll | | faculty | | grade | | school | | student | +----------------+ 8 rows in set (0.04 sec) mysql> SELECT * FROM student; +--------+-----------+---------+-------+-------+---------+---------+ | stuId | fname | lname | major | minor | credits | advisor | +--------+-----------+---------+-------+-------+---------+---------+ | 100000 | Tony | Hawk | CSCI | CINF | 40 | 1011 | | 100001 | Mary | Hawk | CSCI | CINF | 35 | 1011 | | 100002 | David | Hawk | CSCI | ITEC | 66 | 1011 | | 100003 | Catherine | Lim | ITEC | CINF | 20 | 1017 | | 100004 | Larry | Johnson | ITEC | NULL | 66 | 1017 | | 100005 | Linda | Johnson | CINF | ENGL | 13 | 1015 | | 100006 | Lillian | Johnson | CINF | ITEC | 18 | 1015 | | 100007 | Ben | Zico | NULL | NULL | 16 | NULL | | 100008 | Bill | Ching | ARTS | ENGL | 90 | 1018 | | 100009 | Linda | King | ARTS | CSCI | 125 | 1018 | +--------+-----------+---------+-------+-------+---------+---------+ 10 rows in set (0.00 sec) mysql>