luke johnson er diagram · luke johnson er diagram this has been modified to match what is actually...

15
Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there is not one required in the original specs of the schema.

Upload: others

Post on 01-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there is not one required in the original specs of the schema.

Page 2: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Schema Tables: create table exam(ename varchar(20) primary key,date_created datetime,points int not null); create table questions(qnumber int not null, ename varchar(20), foreign key (ename) references exam(ename),correct char(1), points int not null, qtext varchar(1000), primary key(qnumber,ename)); create table choice(ename varchar(20), qnumber int not null, foreign key (qnumber,ename) references questions(qnumber,ename), choice char(1) not null, ctext varchar(1000), primary key(ename,qnumber,choice)); create table student(id char(10) primary key, name varchar(20), major varchar(20), password varchar(20) not null); create table takes(ename varchar(20), foreign key (ename) references exam(ename),id char(10), foreign key (id) references student(id),score decimal(3,2), primary key(id,ename)); create table studentqa(id char(10), foreign key (id) references student(id),ename varchar(20), foreign key (ename) references exam(ename), qnumber int not null, foreign key (qnumber) references questions(qnumber), point int, answer char(1),primary key (id,ename,qnumber));

Triggers: create trigger studentqa_insert before insert on studentqa for each row begin declare correcta char(1); declare pointsa int; select correct from questions where ename = NEW.ename and qnumber = NEW.qnumber into correcta;

select points from questions where ename = NEW.ename and qnumber = NEW.qnumber into pointsa; if correcta = NEW.answer then set NEW.point = pointsa; end if; end//

Page 3: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

create trigger student_insert before insert on student for each row begin

declare epass varchar(20); select encode(NEW.password,"!@#$%^&**") into epass;

set NEW.password = epass; end// create trigger update_takes after insert on studentqa for each row begin declare exampoints int; declare totalpoints int; select points from exam where ename = NEW.ename into exampoints; select sum(point) from studentqa where ename = NEW.ename and id = NEW.id into totalpoints;

update takes set score = totalpoints / exampoints where id = NEW.id and ename = NEw.ename;

end//

create trigger update_points after insert on questions for each row begin declare totalpoints int; set totalpoints = (select sum(points) from questions where NEW.ename=ename ); update exam set points = totalpoints where ename = NEW.ename; end// | student_insert | INSERT | student | begin declare epass varchar(20); select encode(NEW.password,"!@#$%^&**") into epass; set NEW.password = epass; end

Procedures: create procedure create_question(num int(11), ename varchar(20), points int (11), qtext varchar(1000)) BEGIN insert into questions values(num,ename,NULL, points, qtext); end// create procedure set_answer(e varchar(20),qnum int(11),cho char(1))

Page 4: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

BEGIN Update questions set correct=cho where ename=e and qnumber=qnum; end// create procedure create_choice(ename varchar(20), qnum int(11), choice char(1), ctext varchar(1000)) BEGIN insert into choice values(ename,qnum,choice,ctext); end// create procedure create_student(id char(10), name varchar(20), major varchar(20)) BEGIN insert into student values(id,name,major,"123"); end// create procedure create_exam(name varchar(20)) BEGIN insert into exam values(name,NOW(),0); end// create procedure assign_exam(ename varchar(20),sid char(10)) BEGIN insert into takes values(ename,sid,NULL); end//

Functions: CREATE FUNCTION getPass(pass VARCHAR(20)) RETURNS VARCHAR(20) BEGIN DECLARE result CHAR(20); SELECT encode(pass,"!@#$%^&**") into result; RETURN result; END; ;

Using the project Log in as the cs3425gr

Page 5: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

[ldjohnso@colossus ~]$ mysql -h classdb.it.mtu.edu -u cs3425gr -p cs3425gr Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 81360 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [cs3425gr]> use ldjohnso Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [ldjohnso]>

i Create a user Alice: Note: Initial password is 123 In order to create a new user call the procedure create_student which has the parameters in this order. Id then NAME then Major

MariaDB [ldjohnso]> call create_student("alice","Alice","CS"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> select * from student; +-------+-------+-------+----------+ | id | name | major | password | +-------+-------+-------+----------+ | alice | Alice | CS | `N | +-------+-------+-------+----------+ 1 row in set (0.00 sec)

ii Create exam: quiz77 Call the procedure create_exam whose only input is the exam name. The data and time created will be calculated automatically along with the number of total points.

MariaDB [ldjohnso]> call create_exam("quiz77"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> select * from exam;

Page 6: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

+--------+---------------------+--------+ | ename | date_created | points | +--------+---------------------+--------+ | quiz77 | 2017-04-24 17:16:51 | 0 | +--------+---------------------+--------+ 1 row in set (0.00 sec)

Iii First create the questions Call the procedure create_questions which has the parameters in this order Question number (int), exam that it belongs to, number of points (int), and finally the question text.

MariaDB [ldjohnso]> call create_question(1,"quiz77",3,"What is a delimiter?"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_question(2,"quiz77",4,"How do you drop a table?"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_question(3,"quiz77",3,"How do you update a table?"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> select * from questions; +---------+--------+---------+--------+----------------------------+ | qnumber | ename | correct | points | qtext | +---------+--------+---------+--------+----------------------------+ | 1 | quiz77 | NULL | 3 | What is a delimiter? | | 2 | quiz77 | NULL | 4 | How do you drop a table? | | 3 | quiz77 | NULL | 3 | How do you update a table? | +---------+--------+---------+--------+----------------------------+ 3 rows in set (0.00 sec)

Next we need to set the correct answers. Then we can make the choices. To set the correct answer call the procedure set_answer. It’s parameters are as follows. The the exam name,question number, then the correct choice as a single char.

MariaDB [ldjohnso]> call set_answer("quiz77",1,'C'); Query OK, 1 rows affected (0.00 sec) MariaDB [ldjohnso]> call set_answer("quiz77",2,'D'); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call set_answer("quiz77",3,'C'); Query OK, 1 row affected (0.01 sec)

Page 7: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

MariaDB [ldjohnso]> select * from questions; +---------+--------+---------+--------+----------------------------+ | qnumber | ename | correct | points | qtext | +---------+--------+---------+--------+----------------------------+ | 1 | quiz77 | C | 3 | What is a delimiter? | | 2 | quiz77 | D | 4 | How do you drop a table? | | 3 | quiz77 | C | 3 | How do you update a table? | +---------+--------+---------+--------+----------------------------+ 3 rows in set (0.00 sec)

Next we need to make the choices for each question. Call the procedure create_choice which has the following parameters. Exam name, question number, the choice as a single char, then the text for that choice

MariaDB [ldjohnso]> call create_choice("quiz77",1,"A","a way to limit water flow"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",1,"B","something to make something unlimited"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",1,"C","the char(s) that define the end of a statment in MySQL"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",2,"A","by throwing it out the window"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",2,"B","by drop kicking it"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",2,"C","by picking it up and droping it"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",2,"D","by using the drop table function in MySQL"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",3,"A","update table tablename"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> call create_choice("quiz77",3,"B","update table tablename where id = 'something'"); Query OK, 1 row affected (0.00 sec)

Page 8: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

MariaDB [ldjohnso]> call create_choice("quiz77",3,"C","update table tablename set id = 'something' where id = 'something'"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> select * from choice; +--------+---------+--------+--------------------------------------------------------------------+ | ename | qnumber | choice | ctext | +--------+---------+--------+--------------------------------------------------------------------+ | quiz77 | 1 | A | a way to limit water flow | | quiz77 | 1 | B | something to make something unlimited | | quiz77 | 1 | C | the char(s) that define the end of a statment in MySQL | | quiz77 | 2 | A | by throwing it out the window | | quiz77 | 2 | B | by drop kicking it | | quiz77 | 2 | C | by picking it up and droping it | | quiz77 | 2 | D | by using the drop table function in MySQL | | quiz77 | 3 | A | update table tablename | | quiz77 | 3 | B | update table tablename where id = 'something' | | quiz77 | 3 | C | update table tablename set id = 'something' where id = 'something' | +--------+---------+--------+--------------------------------------------------------------------+ 10 rows in set (0.00 sec)

So, the exam is all made now we need to assign Alice the exam in the database. Call the procedure assign_exam which has the parameters Exam name, then student id. Assigned exams have a score of NULL in the takes tabe.

MariaDB [ldjohnso]> call assign_exam("quiz77","alice"); Query OK, 1 row affected (0.00 sec) MariaDB [ldjohnso]> select * from takes; +--------+-------+-------+ | ename | id | score | +--------+-------+-------+ | quiz77 | alice | NULL | +--------+-------+-------+ 1 row in set (0.00 sec)

Page 9: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Logging in: Here is the login screen

But Alice’s credentials in. Which are Username = alice //username is the id of the student Password = 123 //123 is the initial password

Page 10: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

IF you entered in the right info you should be taken to this page.

No click on the button that says take test and you should be taken to this screen

Page 11: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Now I will answer A D C

Page 12: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Before I submit here is the studentqa table. This table holds all the students answers to questions.

MariaDB [ldjohnso]> select * from studentqa; Empty set (0.00 sec)

I will not push the button that says submit answers and it will now take me to this page

Page 13: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

Here is the studentqa table now

MariaDB [ldjohnso]> select * from studentqa; Empty set (0.01 sec)

Page 14: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

MariaDB [ldjohnso]> select * from studentqa; +-------+--------+---------+-------+--------+ | id | ename | qnumber | point | answer | +-------+--------+---------+-------+--------+ | alice | quiz77 | 1 | 0 | A | | alice | quiz77 | 2 | 4 | D | | alice | quiz77 | 3 | 3 | C | +-------+--------+---------+-------+--------+ 3 rows in set (0.00 sec)

Also here is the takes table after the submit

MariaDB [ldjohnso]> select * from takes; +--------+-------+-------+ | ename | id | score | +--------+-------+-------+ | quiz77 | alice | 0.58 |

Now click the link on the bottom of page to go back to the home screen Once you are at the home screen you can see that there is an item under previous test

Click on the more info button to be taken to this screen

Page 15: Luke Johnson ER diagram · Luke Johnson ER diagram This has been modified to match what is actually in my database. As you can see there is a password attached to student but there

This feature allows anyone using this to check previous exams.