This commit is contained in:
OMGiTzPomPom 2023-01-19 09:11:42 +01:00
parent 24867f08a8
commit 279452d652
3 changed files with 90 additions and 2 deletions

View File

@ -132,3 +132,22 @@ FROM
GROUP BY
la_date
;
---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 ;

View File

@ -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 ;

View File

@ -159,3 +159,28 @@ LIKE
ORDER BY
V.ville_nom ASC
;
--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;