mySQL TRIGGER problem

Reply

Join Date: May 2008
Posts: 1
Reputation: M3nTaL is an unknown quantity at this point 
Solved Threads: 0
M3nTaL M3nTaL is offline Offline
Newbie Poster

mySQL TRIGGER problem

 
0
  #1
May 8th, 2008
Hello,

I'm having some sintax problems using PL/SQL in mySQL TRIGGERS.. I need some help please .
Here is the code:

  1. CREATE TRIGGER modificou
  2. AFTER UPDATE ON monitor
  3. FOR EACH ROW
  4. BEGIN
  5. IF NOT EXISTS(SELECT estado_tmp FROM alteracoes WHERE id_tmp = OLD.id)
  6. THEN
  7. INSERT INTO alteracoes VALUES(OLD.id,NEW.estado);
  8. ELSE
  9. UPDATE alteracoes SET estado_tmp = NEW.estado WHERE id_tmp = OLD.id;
  10. END IF;
  11. END modificou;

What could be wrong?? For testing I'm using phpmyadmin 2.11.1

Thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: mySQL TRIGGER problem

 
0
  #2
May 9th, 2008
hi,
what is the error message?

Your trigger will be fired AFTER update, and, obviously, it were to catch update errors IF the record to be updated does not exist in your table. Well, if that record does not exist, update would not be execute, therefore (i believe so) AFTER-update trigger will never be fired.

If you want to prevent failure, if a record to be inserted already exists (that would lead into duplicate primary key), you might use
  1. INSERT INTO table (...) VALUES (...) ON DUPLICATE KEY UPDATE ....
krs,
tesu
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC