Précédent   Forum des professionnels en informatique > Bases de données > MySQL > SQL Procédural
SQL Procédural Forum d'entraide sur les triggers, les procédures stockées et les fonctions en MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 22/12/2010, 11h33   #1
Candidat au titre de Membre du Club
 
Inscription : juin 2010
Messages : 56
Détails du profil
Informations forums :
Inscription : juin 2010
Messages : 56
Points : 10
Points : 10
Par défaut trigger after update et 2 tables

Bonjour

j'ai deux tables
tb1 et tb2
avec les mêmes champs id et nom

je veux que tb2 reflète tout ce qui se passe dans tb1

Code :
1
2
3
4
5
CREATE TRIGGER trg_un AFTER UPDATE ON tb1
 FOR EACH ROW
 BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;
END;
ne marche pas
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 4


quelle est la bonne syntaxe pour mysql 5 ?

merci
jeorcal est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/12/2010, 15h15   #2
Modérateur
 
Avatar de CinePhil
 
Homme Philippe Leménager
Ingénieur d'études en informatique
Inscription : août 2006
Messages : 10 977
Détails du profil
Informations personnelles :
Nom : Homme Philippe Leménager
Âge : 48
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Ingénieur d'études en informatique
Secteur : Enseignement

Informations forums :
Inscription : août 2006
Messages : 10 977
Points : 18 221
Points : 18 221
Envoyer un message via MSN à CinePhil
C'est peut-être un problème de DELIMITER ?
Code :
1
2
3
4
5
6
CREATE TRIGGER trg_un AFTER UPDATE ON tb1
 FOR EACH ROW
DELIMITER// 
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;
END//
__________________
Philippe Leménager. Ingénieur d'étude à l'École Nationale de Formation Agronomique.
Mon blog sur la conception des BDD, le langage SQL, le PHP avec Zend Framework...
« Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
À la maison comme au bureau, j'utilise Mandriva Linux ou Mageïa ! Soutenons l'industrie logicielle française !
Linuxiens, comptez-vous !
CinePhil est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/12/2010, 20h58   #3
Candidat au titre de Membre du Club
 
Inscription : juin 2010
Messages : 56
Détails du profil
Informations forums :
Inscription : juin 2010
Messages : 56
Points : 10
Points : 10
j'obtiens

Citation:
Erreur

Il semble qu'il y ait une erreur dans votre requête SQL. Le message ci-bas peut vous aider à en trouver la cause.

ERROR: Ponctuation invalide @ 66
STR: //
SQL: CREATE TRIGGER trg_un AFTER UPDATE ON tb1
FOR EACH ROW
DELIMITER//
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;CREATE TRIGGER trg_un AFTER UPDATE ON tb1
FOR EACH ROW
DELIMITER//
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;CREATE TRIGGER trg_un AFTER UPDATE ON tb1
FOR EACH ROW
DELIMITER//
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;


requête SQL:

CREATE TRIGGER trg_un AFTER UPDATE ON tb1 FOR EACH ROW DELIMITER// BEGIN UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;

MySQL a réponduocumentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom' at line 3
jeorcal est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/12/2010, 22h49   #4
Membre Expert
 
Avatar de Madfrix
 
Inscription : juin 2007
Messages : 2 278
Détails du profil
Informations personnelles :
Localisation : France, Gironde (Aquitaine)

Informations forums :
Inscription : juin 2007
Messages : 2 278
Points : 2 324
Points : 2 324
je pense qu'il faut un espace entre DELIMITER et le delimiteur à proprement parler

Code sql :
1
2
3
4
5
6
7
 
DELIMITER $$
CREATE TRIGGER trg_un AFTER UPDATE ON tb1
FOR EACH ROW
BEGIN
UPDATE tb2 INNER JOIN tb1 ON tb1.id = tb2.id SET tb2.nom = tb1.nom ;
END $$
Madfrix est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/12/2010, 23h15   #5
Candidat au titre de Membre du Club
 
Inscription : juin 2010
Messages : 56
Détails du profil
Informations forums :
Inscription : juin 2010
Messages : 56
Points : 10
Points : 10
génial ça marche

merci mille fois
jeorcal est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 09h26   #6
Candidat au titre de Membre du Club
 
Inscription : juin 2010
Messages : 56
Détails du profil
Informations forums :
Inscription : juin 2010
Messages : 56
Points : 10
Points : 10
par contre j'arrive pas à le faire marcher entre 2 base de données

je crée le trigger dans db1 :

Code :
1
2
3
4
5
6
DELIMITER $$
CREATE TRIGGER trg_2db AFTER UPDATE ON db1.tb1
FOR EACH ROW
BEGIN
UPDATE db2.tb1 INNER JOIN db1.tb1 ON db1.tb1.id = db2.tb1.id SET db2.tb1.nom = db1.tb1.nom ;
END $$
jeorcal est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h36.


 
 
 
 
Partenaires

Hébergement Web