InQuire/schema.sql

46 lines
1.8 KiB
MySQL
Raw Normal View History

2018-12-11 16:08:53 +01:00
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS question;
DROP TABLE IF EXISTS subjects;
CREATE TABLE user (
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
lecturer INTEGER NOT NULL
);
CREATE TABLE question (
question_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_id INTEGER NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
question_text TEXT NOT NULL,
upvotes INTEGER NOT NULL,
FOREIGN KEY (subject_id) REFERENCES subject (subject_id)
);
CREATE TABLE subject (
subject_id INTEGER PRIMARY KEY AUTOINCREMENT,
subject_name TEXT UNIQUE NOT NULL,
user_id INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (user_id)
);
INSERT INTO user (username, password, lecturer) VALUES ('admin','admin',1);
INSERT INTO user (username, password, lecturer) VALUES ('jassem','jassem',1);
INSERT INTO user (username, password, lecturer) VALUES ('user','user',0);
INSERT INTO user (username, password, lecturer) VALUES ('max','max',0);
INSERT INTO user (username, password, lecturer) VALUES ('leniwy_student31','password',0);
INSERT INTO subject (subject_name, user_id) VALUES ('Nudny przedmiot',1);
INSERT INTO subject (subject_name, user_id) VALUES ('TPI - najlepszy przedmiot',2);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (1, 'Nudne pytanie',0);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Czy pytania będą proste?',78);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Czy to będzie na egzaminie?',111);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Nic nie rozumiem.',6);
INSERT INTO question (subject_id, question_text, upvotes) VALUES (2, 'Chcę zdaaaaać',9);
select * from user;
select * from question;
select * from subject;