triggers
This commit is contained in:
parent
24867f08a8
commit
279452d652
@ -131,4 +131,23 @@ FROM
|
||||
commandes C
|
||||
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 ;
|
@ -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 ;
|
||||
|
@ -158,4 +158,29 @@ LIKE
|
||||
'SAINT-%'
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user