-- Création de la base de donnée (trouvetarecette)

CREATE DATABASE IF NOT EXISTS `trouvetarecette`;
USE `trouvetarecette`;

-- Suppression des tables
ALTER TABLE IF EXISTS `recettes` DROP FOREIGN KEY IF EXISTS recettes_categorie;
ALTER TABLE IF EXISTS `bind_ir` DROP FOREIGN KEY IF EXISTS bind_ingredients_id;
ALTER TABLE IF EXISTS `bind_ir` DROP FOREIGN KEY IF EXISTS bind_recettes_id;

DROP TABLE IF EXISTS `bind_ir`;
DROP TABLE IF EXISTS `recettes`;
DROP TABLE IF EXISTS `categorie`;
DROP TABLE IF EXISTS `ingredients`;
DROP TABLE IF EXISTS `fiches`;

-- Création de la table Catégorie

CREATE TABLE IF NOT EXISTS `categorie` (
    categorie_id SMALLINT(6) PRIMARY KEY AUTO_INCREMENT NOT NULL,
    categorie_nom ENUM('Crèmes de base','Pâtes de base','Glaçages','Biscuits','Entremets','Gâteaux','Cakes','Mousses','Glaces et Sorbets','Compotés','Inserts','Tartes','Pâte à tartiner','Meringues','Mignardises','Macarons','Décorations')
)
ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

--Creation ingredients

CREATE TABLE IF NOT EXISTS `ingredients` (
    ingredients_id SMALLINT(6) PRIMARY KEY AUTO_INCREMENT NOT NULL,
    ingredients_nom VARCHAR(50) NOT NULL UNIQUE,
    ingredients_marque VARCHAR(50)
) 
ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;


-- Création de la table principale recettes

CREATE TABLE IF NOT EXISTS `recettes` (
    recettes_id SMALLINT(6) PRIMARY KEY AUTO_INCREMENT NOT NULL,
    recettes_nom VARCHAR(100) NOT NULL UNIQUE,
    recettes_categorie SMALLINT(6) NOT NULL,
    recettes_frequence VARCHAR(50),
    recettes_date DATE,
    recettes_approuve BOOLEAN,
    recettes_etapes TEXT NOT NULL,
    FOREIGN KEY (recettes_categorie) REFERENCES categorie(categorie_id)
)
ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Création de la table Fiches (pour les fiches technique complètes)

CREATE TABLE IF NOT EXISTS `fiches` (
    fiches_id SMALLINT(6) PRIMARY KEY AUTO_INCREMENT NOT NULL,
    fiches_nom VARCHAR(100) NOT NULL,
    fiches_saison ENUM('Printemps','ETE','Automne','Hiver') NOT NULL,
    fiches_approuve BOOLEAN
)
ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Creation table liaison
CREATE TABLE IF NOT EXISTS `bind_ir` (
    bind_recettes_id SMALLINT(6) NOT NULL,
    bind_ingredients_id SMALLINT(6) NOT NULL,
    bind_quantite SMALLINT(6) NOT NULL,
    bind_unite VARCHAR(4) DEFAULT 'Gr',
    FOREIGN KEY (bind_ingredients_id) REFERENCES ingredients (ingredients_id) ON DELETE CASCADE,
    FOREIGN KEY (bind_recettes_id) REFERENCES recettes (recettes_id) ON DELETE CASCADE,
    PRIMARY KEY (bind_recettes_id,bind_ingredients_id),
    UNIQUE (bind_recettes_id,bind_ingredients_id)
)
ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Ajout de contenu à la tables ingredients

INSERT INTO ingredients (ingredients_nom,ingredients_marque) 
VALUES
('Sucre','Tirlemont'),
('Levure','Brugmann'),
('Beurre','Inex'),
('Lait','Inex');

-- Ajout des catégories

INSERT INTO categorie (categorie_nom)
VALUES
('Gâteaux'),
('Cakes'),
('Crèmes de base'),
('Pâtes de base'),
('Tartes'),
('Compotés'),
('Glaces et Sorbets'),
('Entremets');


-- Ajout de recettes 

INSERT INTO recettes (recettes_nom,recettes_categorie,recettes_frequence,recettes_date,recettes_approuve,recettes_etapes)
VALUES
('Javanais',1,'Souvent','2022-04-28',1,'Il faut faire'),
('Merveilleux',2,'Jamais','2020-12-28',0,'La meringue '),
('Cake chocolat',2,'Très souvent','2020-10-01',1,'Il ne faut pas')
;
INSERT INTO `bind_ir` (bind_recettes_id,bind_ingredients_id,bind_quantite,bind_unite)
VALUES
    (1,1,287,DEFAULT),
    (1,4,654,DEFAULT),
    (1,3,465,DEFAULT),
    (2,3,400,DEFAULT),
    (3,4,500,DEFAULT),
    (1,2,187,DEFAULT);

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: