mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-07-28 21:59:50 +00:00
il n'y a pas eu de leak de mot de passe ici ;)
This commit is contained in:
47
bdd_proj.sql
Normal file → Executable file
47
bdd_proj.sql
Normal file → Executable file
@ -11,6 +11,8 @@ CREATE TABLE posts (
|
||||
title VARCHAR(32),
|
||||
url VARCHAR(32),
|
||||
content TEXT,
|
||||
short varchar(256),
|
||||
dt DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
categorie INT,
|
||||
author INT
|
||||
);
|
||||
@ -33,11 +35,10 @@ CREATE TABLE tag (
|
||||
|
||||
CREATE TABLE categories (
|
||||
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
url VARCHAR(32),
|
||||
name VARCHAR(32)
|
||||
);
|
||||
|
||||
CREATE TABLE user (
|
||||
CREATE TABLE users (
|
||||
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(128),
|
||||
linkedin VARCHAR(560)
|
||||
@ -45,13 +46,47 @@ CREATE TABLE user (
|
||||
|
||||
|
||||
ALTER TABLE post_tag
|
||||
ADD FOREIGN KEY (post_id) REFERENCES posts(post_id);
|
||||
ADD FOREIGN KEY (post_id) REFERENCES posts(id);
|
||||
|
||||
ALTER TABLE post_tag
|
||||
ADD FOREIGN KEY (categorie) REFERENCES tag(categorie);
|
||||
ADD FOREIGN KEY (categorie) REFERENCES tag(id);
|
||||
|
||||
ALTER TABLE posts
|
||||
ADD FOREIGN KEY (categorie) REFERENCES categories(id)
|
||||
ADD FOREIGN KEY (categorie) REFERENCES categories(id);
|
||||
|
||||
ALTER TABLE posts
|
||||
ADD FOREIGN KEY (author) REFERENCES users(id)
|
||||
ADD FOREIGN KEY (author) REFERENCES users(id);
|
||||
|
||||
|
||||
-- posts
|
||||
INSERT INTO posts (title, url, content, short, categorie, author)
|
||||
VALUES ('pokemon', 'pokemon', 'cacacacacacacacacacacacaca\r\ncacacacacacacacacacacacaca\r\ncacacacacacacacacacacacaca', 'caca', 1, 2),
|
||||
('Pokemon Go', 'pokemon-go', 'I PLAY POKEMON GO EVERYDAY', 'I PLAY POKEMON GO', 2, 1);
|
||||
|
||||
-- users
|
||||
INSERT INTO users (username, linkedin) VALUES ('Florian Bouillon', NULL), ('Adrien huchet', 'adrienhuchet');
|
||||
|
||||
-- categories
|
||||
INSERT INTO categories (name) VALUES ('devops'), ('ops'), ('dev'), ('digi');
|
||||
|
||||
-- requete 1 :
|
||||
-- recuperer 10 posts avec la categorie associé la date du post et les 256 premiers mots du contenu
|
||||
|
||||
SELECT title, short, categorie, url FROM posts
|
||||
LIMIT 10;
|
||||
|
||||
-- requete 2 :
|
||||
-- recuperer 1 post son titre, Categories, dates, contenu, nom_auteur, photo_auteur, lien linkedin
|
||||
|
||||
SELECT post.title as title, post.categorie as categorie, post.date as date, post.content as content, user.username as author, user.linkedin as linkedin
|
||||
FROM post
|
||||
INNER JOIN users BY post.author=user.id
|
||||
LIMIT 1;
|
||||
|
||||
-- requette 3 : comme la 1 sauf uniquement les 6 posts les plus r<>cents
|
||||
-- requete lanc<6E>e lors sur la page d'accueil
|
||||
SELECT title, categories.name as categorie, dt as date, short as content
|
||||
FROM posts
|
||||
INNER JOIN categories ON categories.id=posts.categorie
|
||||
ORDER BY date DESC
|
||||
LIMIT 6;
|
||||
|
Reference in New Issue
Block a user