Mise à jour de 'script.SQL'

master
Leni BEAULATON 1 month ago
parent 5f170c44da
commit d21844dcc0

@ -1,12 +1,120 @@
INSERT INTO Commentary (id_comment, quote, users, dateC, comment)
VALUES
('CMT001', 'Q001', 'U001', '2024-10-01', 'This quote really resonates with me.'),
('CMT002', 'Q002', 'U002', '2024-10-02', 'A timeless piece of wisdom.'),
('CMT003', 'Q003', 'U003', '2024-10-03', 'I disagree with this viewpoint.'),
('CMT004', 'Q004', 'U001', '2024-10-04', 'Absolutely love this quote!'),
('CMT005', 'Q005', 'U004', '2024-10-05', 'Very motivational, thanks for sharing!'),
('CMT006', 'Q006', 'U005', '2024-10-06', 'This makes me reflect on life.'),
('CMT007', 'Q007', 'U006', '2024-10-07', 'I find this quote very inspiring.'),
('CMT008', 'Q008', 'U007', '2024-10-08', 'I think theres more to this than meets the eye.'),
('CMT009', 'Q009', 'U008', '2024-10-09', 'Such a powerful statement!'),
('CMT010', 'Q010', 'U009', '2024-10-10', 'This is one of my favorites!');
-- Suppression des tables
DROP TABLE IF EXISTS Commentary;
DROP TABLE IF EXISTS Favorite;
DROP TABLE IF EXISTS Quote;
DROP TABLE IF EXISTS Caracter;
DROP TABLE IF EXISTS Source;
DROP TABLE IF EXISTS Record_quiz;
DROP TABLE IF EXISTS Quiz_Question;
DROP TABLE IF EXISTS Quiz;
DROP TABLE IF EXISTS Question;
DROP TABLE IF EXISTS Admin;
DROP TABLE IF EXISTS Users;
DROP TABLE IF EXISTS Image;
-- Création des tables
CREATE TABLE Image(
id_img SERIAL PRIMARY KEY,
imgPath varchar(100) NOT NULL UNIQUE
);
CREATE TABLE Users(
id_user varchar(5) PRIMARY KEY,
username varchar(50) NOT NULL,
email varchar(50) NOT NULL,
pssword varchar(100) NOT NULL,
img SERIAL NOT NULL,
creation date NOT NULL,
CONSTRAINT unique_col UNIQUE (email),
CONSTRAINT fk_img FOREIGN KEY(img) REFERENCES Image(id_img)
);
CREATE TABLE Admin(
users varchar(5) PRIMARY KEY,
CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user)
);
CREATE TABLE Question(
id_question SERIAL PRIMARY KEY,
texte text NOT NULL UNIQUE,
answerA varchar(30) NOT NULL,
answerB varchar(30) NOT NULL,
answerC varchar(30) NOT NULL,
answerD varchar(30) NOT NULL,
cAnswer varchar(30) NOT NULL,
CONSTRAINT check_cAnswer CHECK (cAnswer = answerA OR cAnswer = answerB OR cAnswer = answerC OR cAnswer = answerD)
);
CREATE TABLE Quiz(
id_quiz SERIAL PRIMARY KEY,
levelQ numeric NOT NULL,
timer numeric NOT NULL
);
CREATE TABLE Quiz_Question(
quiz SERIAL NOT NULL,
question SERIAL NOT NULL,
PRIMARY KEY (quiz, question),
CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz),
CONSTRAINT fk_question FOREIGN KEY(question) REFERENCES Question(id_question)
);
CREATE TABLE Record_quiz(
users varchar(5) NOT NULL,
quiz SERIAL NOT NULL,
nbPoint numeric DEFAULT '0',
timeQ numeric DEFAULT '0',
PRIMARY KEY (users, quiz),
CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user),
CONSTRAINT fk_quiz FOREIGN KEY(quiz) REFERENCES Quiz(id_quiz),
CONSTRAINT err_nbPoint CHECK(nbPoint >= 0),
CONSTRAINT err_timeQ CHECK(timeQ >= 0)
);
CREATE TABLE Source(
id_source SERIAL PRIMARY KEY,
title varchar(100) NOT NULL,
dateS date NOT NULL
);
CREATE TABLE Caracter(
id_caracter SERIAL PRIMARY KEY,
caracter varchar(100) NOT NULL,
img_path varchar(100) NOT NULL
);
CREATE TABLE Quote(
id_quote varchar(50) PRIMARY KEY,
content text NOT NULL,
likes numeric DEFAULT '0',
langue char(2) NOT NULL,
isValide boolean NOT NULL DEFAULT 'false',
reason varchar(100) NOT NULL,
id_caracter SERIAL NOT NULL,
id_source SERIAL NOT NULL,
id_user_verif varchar(5) NOT NULL,
CONSTRAINT fk_caracter FOREIGN KEY(id_caracter) REFERENCES Caracter(id_caracter),
CONSTRAINT fk_source FOREIGN KEY(id_source) REFERENCES Source(id_source),
CONSTRAINT fk_userverif FOREIGN KEY(id_user_verif) REFERENCES Users(id_user),
CONSTRAINT err_nbLike CHECK (likes >= 0),
CONSTRAINT err_language CHECK (langue = 'fr' OR langue = 'en')
);
CREATE TABLE Favorite(
users varchar(5) NOT NULL,
quote varchar(50) NOT NULL,
PRIMARY KEY (users, quote),
CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote),
CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user)
);
CREATE TABLE Commentary(
id_comment varchar(100) PRIMARY KEY,
quote varchar(50) NOT NULL,
users varchar(5) NOT NULL,
dateC date NOT NULL,
comment text NOT NULL,
CONSTRAINT fk_quote FOREIGN KEY(quote) REFERENCES Quote(id_quote),
CONSTRAINT fk_user FOREIGN KEY(users) REFERENCES Users(id_user)
);

Loading…
Cancel
Save