-
Notifications
You must be signed in to change notification settings - Fork 3
/
sql.sql
executable file
·101 lines (100 loc) · 3.53 KB
/
sql.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
-- SMALLINT UNSIGNED => max is 65535
-- 1 documento 50*25(1250)
-- 50 documents 1250*50 = 62500 max.
-- SMALLINT(5) UNSIGNED
-- max input for question: 600 characters
-- max title, user,: 50 characters
-- max 25 answers for a question
-- max 50 questions for 1 document
-- answers and questions: max 600 carachters
CREATE DATABASE IF NOT EXISTS simple_quiz;
USE simple_quiz;
DROP TABLE IF EXISTS simple_quiz.percentage;
DROP TABLE IF EXISTS simple_quiz.randomness;
DROP TABLE IF EXISTS simple_quiz.choices;
DROP TABLE IF EXISTS simple_quiz.questions;
DROP TABLE IF EXISTS simple_quiz.group;
DROP TABLE IF EXISTS simple_quiz.document;
DROP TABLE IF EXISTS simple_quiz.users;
-- Table structure for table users
-- DROP TABLE IF EXISTS simple_quiz.users;
CREATE TABLE IF NOT EXISTS users (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
username varchar(100) NOT NULL,
password varchar(100) NOT NULL,
email varchar(320) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8;
-- insert username and password for first access
INSERT INTO simple_quiz.users (username, password) VALUES
('admin', 'password');
-- Hash password
UPDATE users
SET password = MD5(password)
WHERE id = 1;
-- create table document
-- this is the html document
-- DROP TABLE IF EXISTS simple_quiz.document;
CREATE TABLE IF NOT EXISTS document (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
title varchar(50) NOT NULL,
coach varchar(50) NOT NULL,
mail varchar(320) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB CHARSET=utf8;
-- Dump data
-- example of INSERT
-- INSERT INTO simple_quiz.document (title,coach,mail) VALUES
-- ('test','test','test');
-- create table group
-- contains category/subject
-- and numbers of questions
-- DROP TABLE IF EXISTS simple_quiz.group;
CREATE TABLE IF NOT EXISTS simple_quiz.group (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
category VARCHAR(50) NOT NULL,
numQuestions SMALLINT(5) UNSIGNED NOT NULL,
id_document SMALLINT(5) UNSIGNED,
PRIMARY KEY (id),
FOREIGN KEY(id_document) REFERENCES document(id)
) ENGINE=InnoDB CHARSET=utf8;
-- create table questions
-- DROP TABLE IF EXISTS simple_quiz.questions;
CREATE TABLE IF NOT EXISTS simple_quiz.questions (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
question VARCHAR(600) NOT NULL,
numAnswers SMALLINT(5) UNSIGNED NOT NULL,
id_group SMALLINT(5) UNSIGNED,
PRIMARY KEY (id),
FOREIGN KEY(id_group) REFERENCES simple_quiz.group(id)
) ENGINE=InnoDB CHARSET=utf8;
-- create table answers
-- DROP TABLE IF EXISTS simple_quiz.choices;
CREATE TABLE IF NOT EXISTS simple_quiz.choices(
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
answer VARCHAR(600) NOT NULL,
id_questions SMALLINT(5) UNSIGNED,
isRight BOOLEAN DEFAULT 0,
PRIMARY KEY (id),
FOREIGN KEY(id_questions) REFERENCES questions(id)
) ENGINE=InnoDB CHARSET=utf8;
-- create table randomness
-- DROP TABLE IF EXISTS simple_quiz.randomness;
CREATE TABLE IF NOT EXISTS simple_quiz.randomness (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
isRandom BOOLEAN DEFAULT NULL,
id_titleR SMALLINT(5) UNSIGNED,
PRIMARY KEY (id),
FOREIGN KEY(id_titleR) REFERENCES document(id)
) ENGINE=InnoDB CHARSET=utf8;
-- create table percentage
-- DROP TABLE IF EXISTS simple_quiz.percentage;
CREATE TABLE IF NOT EXISTS simple_quiz.percentage (
id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
percent SMALLINT(5) UNSIGNED,-- max 100 for 100%
id_titleP SMALLINT(5) UNSIGNED UNSIGNED,
PRIMARY KEY (id),
FOREIGN KEY(id_titleP) REFERENCES document(id)
) ENGINE=InnoDB CHARSET=utf8;
UPDATE users
SET email = "email";