diff --git a/TD2/ecommerce_1.sql b/TD2/ecommerce_1.sql index b001ae2..0442e83 100644 --- a/TD2/ecommerce_1.sql +++ b/TD2/ecommerce_1.sql @@ -131,4 +131,23 @@ FROM commandes C GROUP BY la_date -; \ No newline at end of file +; + +---trigger 7 + +DELIMITER // +CREATE TRIGGER before_insert_commandes_lignes + BEFORE INSERT + ON commandes_lignes FOR EACH ROW +BEGIN + SET NEW.commande_ligne_prix_total = NEW.commande_ligne_quantite * NEW.commande_ligne_prix_unitaire; +END // +DELIMITER ; +DELIMITER // +CREATE TRIGGER before_update_commandes_lignes + BEFORE UPDATE + ON commandes_lignes FOR EACH ROW +BEGIN + SET NEW.commande_ligne_prix_total = NEW.commande_ligne_quantite * NEW.commande_ligne_prix_unitaire; +END // +DELIMITER ; \ No newline at end of file diff --git a/TD2/ecommerce_2.sql b/TD2/ecommerce_2.sql index 23d65a9..167b080 100644 --- a/TD2/ecommerce_2.sql +++ b/TD2/ecommerce_2.sql @@ -85,3 +85,47 @@ LIMIT ; +--trigger 2 + +DELIMITER // +CREATE TRIGGER define_gategory +BEFORE INSERT +ON commandes FOR EACH ROW +BEGIN + SET NEW.categorie_id = + CASE + WHEN + NEW.commande_cache_prix_total < 200 + THEN 1 + WHEN + NEW.commande_cache_prix_total BETWEEN 200 AND 500 + THEN 2 + WHEN + NEW.commande_cache_prix_total BETWEEN 500 AND 1000 + THEN 3 + ELSE 4 + END; +END // +DELIMITER ; + + +DELIMITER // +CREATE TRIGGER define_gategory_update +BEFORE UPDATE +ON commandes FOR EACH ROW +BEGIN + SET NEW.categorie_id = + CASE + WHEN + NEW.commande_cache_prix_total < 200 + THEN 1 + WHEN + NEW.commande_cache_prix_total BETWEEN 200 AND 500 + THEN 2 + WHEN + NEW.commande_cache_prix_total BETWEEN 500 AND 1000 + THEN 3 + ELSE 4 + END; +END // +DELIMITER ; diff --git a/TD2/geographie.sql b/TD2/geographie.sql index e73f375..f505423 100644 --- a/TD2/geographie.sql +++ b/TD2/geographie.sql @@ -158,4 +158,29 @@ LIKE 'SAINT-%' ORDER BY V.ville_nom ASC -; \ No newline at end of file +; + +--Procedure + +DELIMITER // +CREATE PROCEDURE replace_all_dashes_by_spaces_for_villes_saint () +BEGIN + UPDATE villes V + SET V.ville_nom = REPLACE(V.ville_nom, '-', ' ') + WHERE + V.ville_nom + LIKE + 'SAINT-%' + ; +END // +DELIMITER ; + +--Trigger +CREATE TRIGGER trigger_name +{BEFORE | AFTER} {INSERT | UPDATE| DELETE } +ON table_name FOR EACH ROW +trigger_body; + + + +