[MYSQL] Trigger sur Ajout
Fermé
aliasing
Messages postés
8
Date d'inscription
mardi 19 juin 2007
Statut
Membre
Dernière intervention
11 juillet 2007
-
11 juil. 2007 à 11:23
Le marocain - 18 juil. 2009 à 17:25
Le marocain - 18 juil. 2009 à 17:25
A voir également:
- [MYSQL] Trigger sur Ajout
- Mysql community server - Télécharger - Bases de données
- Ajout snap sans rien d'écrit - Forum Snapchat
- Ajout rapide snap - Forum Snapchat
- Demande d'ajout snap qui disparait ✓ - Forum Snapchat
- Impossible d'ajouter des amis sur Snapchat ✓ - Forum Snapchat
3 réponses
Bonjour,
moi aussi j'avais un problème pour les trigger sous Mysql mais j'ai réussi "hamdolilah" à réalisé deux exemples qui marche, bien à vous ts.
voilà un 1er exemple :
delimiter //
CREATE TRIGGER upd_check BEFORE UPDATE ON account
FOR EACH ROW
BEGIN
IF NEW.amount < 0 THEN
SET NEW.amount = 0;
ELSEIF NEW.amount > 100 THEN
SET NEW.amount = 100;
END IF;
END//
delimiter ;
2ème exemple :
drop trigger cont_depart_update;
DELIMITER //
CREATE TRIGGER cont_depart_update AFTER UPDATE ON tacheassigne
FOR EACH ROW
BEGIN
DECLARE idProjet varchar(20);
DECLARE moyenneAcompli varchar(5);
select p.idp into @idProjet
from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where ta.idta=New.idta;
select avg(ta.accompli) into @moyenneAcompli
from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where ta.idta in (select ta.idta from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where p.idp=@idProjet)
group by p.idp;
update projet set accompli=@moyenneAcompli where idp=@idProjet;
END//
delimiter;
/////////////////////////////////////////////////////////////////////////////////
RQ :
* en mysql c'est "NEW" c'est pas comme ORACLE ":NEW"
* utiliser les delimiter (existe aussi au niveau de la console de mysql)
* l'appel des varriables c'est avec "@" et non & comme ORACLE
/////////////////////////////////////////////////////////////////////////////////
moi aussi j'avais un problème pour les trigger sous Mysql mais j'ai réussi "hamdolilah" à réalisé deux exemples qui marche, bien à vous ts.
voilà un 1er exemple :
delimiter //
CREATE TRIGGER upd_check BEFORE UPDATE ON account
FOR EACH ROW
BEGIN
IF NEW.amount < 0 THEN
SET NEW.amount = 0;
ELSEIF NEW.amount > 100 THEN
SET NEW.amount = 100;
END IF;
END//
delimiter ;
2ème exemple :
drop trigger cont_depart_update;
DELIMITER //
CREATE TRIGGER cont_depart_update AFTER UPDATE ON tacheassigne
FOR EACH ROW
BEGIN
DECLARE idProjet varchar(20);
DECLARE moyenneAcompli varchar(5);
select p.idp into @idProjet
from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where ta.idta=New.idta;
select avg(ta.accompli) into @moyenneAcompli
from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where ta.idta in (select ta.idta from projet p inner join tache t on p.idp = t.idp inner join tacheassigne ta on t.idtache = ta.idtache where p.idp=@idProjet)
group by p.idp;
update projet set accompli=@moyenneAcompli where idp=@idProjet;
END//
delimiter;
/////////////////////////////////////////////////////////////////////////////////
RQ :
* en mysql c'est "NEW" c'est pas comme ORACLE ":NEW"
* utiliser les delimiter (existe aussi au niveau de la console de mysql)
* l'appel des varriables c'est avec "@" et non & comme ORACLE
/////////////////////////////////////////////////////////////////////////////////