sicherheitsunterweisung/create_tables.sql

106 lines
2.9 KiB
MySQL
Raw Normal View History

USE sicherheitsunterweisung;
2023-10-19 20:06:28 +02:00
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;
2023-10-19 20:06:28 +02:00
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' ),
2023-10-19 20:06:28 +02:00
( 'Was ist 2+2?', '1', '2', '3', '4', '4' ),
( 'Was ist 0+1?', '1', '2', '3', '4', '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' );