User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 330,010 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,557 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 122 | Replies: 1
Reply
Join Date: May 2008
Posts: 1
Reputation: M3nTaL is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
M3nTaL M3nTaL is offline Offline
Newbie Poster

mySQL TRIGGER problem

  #1  
5 Days Ago
Hello,

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

CREATE TRIGGER modificou
   AFTER UPDATE ON monitor
   FOR EACH ROW
 BEGIN
   IF NOT EXISTS(SELECT estado_tmp FROM alteracoes WHERE id_tmp = OLD.id)
   THEN
       INSERT INTO alteracoes VALUES(OLD.id,NEW.estado);
   ELSE
       UPDATE alteracoes SET estado_tmp = NEW.estado WHERE id_tmp = OLD.id;
   END IF;
 END modificou;

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

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 47
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
tesuji tesuji is offline Offline
Light Poster

Re: mySQL TRIGGER problem

  #2  
3 Days Ago
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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 10:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC