sicherheitsunterweisung/create_tables.sql

117 lines
3.7 KiB
SQL

/*
* Sicherheitsunterweisung
* Copyright (C) 2023 Jason Streifling
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
USE sicherheitsunterweisung;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS instructors;
DROP TABLE IF EXISTS briefings;
DROP TABLE IF EXISTS participants;
DROP TABLE IF EXISTS questions;
DROP TABLE IF EXISTS given_answers;
SET FOREIGN_KEY_CHECKS = 1;
CREATE TABLE instructors (
id INT NOT NULL,
first_name VARCHAR(32) NOT NULL,
last_name VARCHAR(32) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE briefings (
id INT AUTO_INCREMENT,
datetime DATETIME NOT NULL,
location VARCHAR(32) NOT NULL,
document VARCHAR(16) NOT NULL,
as_of DATE NOT NULL,
instructor_id INT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(instructor_id) REFERENCES instructors(id)
);
CREATE TABLE participants (
id INT AUTO_INCREMENT,
first_name VARCHAR(32) NOT NULL,
last_name VARCHAR(32) NOT NULL,
company VARCHAR(32) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE questions (
id INT AUTO_INCREMENT,
question VARCHAR(256) NOT NULL,
answer_1 VARCHAR(64) NOT NULL,
answer_2 VARCHAR(64) NOT NULL,
answer_3 VARCHAR(64) NOT NULL,
answer_4 VARCHAR(64) NOT NULL,
correct_answer INT NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE given_answers (
briefing_id INT NOT NULL,
participant_id INT NOT NULL,
question_id INT NOT NULL,
given_answer INT NOT NULL,
PRIMARY KEY(briefing_id, participant_id, question_id),
FOREIGN KEY(briefing_id) REFERENCES briefings(id),
FOREIGN KEY(participant_id) REFERENCES participants(id),
FOREIGN KEY(question_id) REFERENCES questions(id)
);
INSERT INTO instructors
(id, first_name, last_name)
VALUES
( '100000', 'Jason', 'Streifling' ),
( '100001', 'Peter', 'Enis' );
--INSERT INTO briefings (
-- datetime, location, document, as_of, instructor_id
--) VALUES
-- ( '2023-10-16 17:00:00', 'Werk Langenhagen', 'ICL-1901-LGH', '2021-02-01', '100000' ),
-- ( '2023-10-16 17:05:00', 'Werk Langenhagen', 'ICL-1901-LGH', '2021-02-01', '100001' );
--
--INSERT INTO participants (
-- first_name, last_name, company
--) VALUES
-- ( 'Max', 'Mustermann', 'ABC GmbH' ),
-- ( 'Gustav', 'Gans', 'ABC GmbH' ),
-- ( 'Klara', 'Kakerlake', 'DEF KG' );
--
INSERT INTO questions (
question, answer_1, answer_2, answer_3, answer_4, correct_answer
) VALUES
( 'Was ist 1+1?', '1', '2', '3', '4', '2' ),
( 'Was ist 1+2?', '1', '2', '3', '4', '3' ),
( 'Was ist 2+2?', '1', '2', '3', '4', '4' ),
( 'Was ist 0+1?', '1', '2', '3', 'file://static/test.jpg', '1' );
--
--INSERT INTO given_answers (
-- briefing_id, participant_id, question_id, given_answer
--) VALUES
-- ( '1', '1', '1', '2' ),
-- ( '1', '1', '2', '3' ),
-- ( '1', '1', '3', '3' ),
-- ( '1', '1', '4', '1' ),
-- ( '1', '2', '1', '2' ),
-- ( '1', '2', '2', '3' ),
-- ( '1', '2', '3', '3' ),
-- ( '1', '2', '4', '1' ),
-- ( '2', '3', '1', '2' ),
-- ( '2', '3', '2', '3' ),
-- ( '2', '3', '3', '4' ),
-- ( '2', '3', '4', '1' );