MySQL Forums
Forum List  »  Triggers

Never used triggers before - please help!
Posted by: Adam Bennett
Date: October 02, 2006 03:32AM

Hi,

I have very little knowledge of triggers so forgive me if this is a simple (or impossible) question.

I have a table with a variety of fields one of which is called 'sync'. This field is being used to flag records that need to be synchronised with another (NON SQL) database. I need to add a trigger (or store procedure) to the table to correctly set if the sync flag to 'Y' if any of the data being UPDATEd has changed. This MUST be done at the database level and I do not have the ability to modify the code that write to the database (3rd party code).

What I effectively want to say is:

if (no_fields_updated > 1) OR (no_fields_updated =1 AND field_name <> 'sync') then
set sync = NULL
end

I need to do it in this way as when the data has been sync'd to the other database it issue an update to set sync = 'Y' - this obviously can't be overriden and set to NULL and the sync process would then loop forever.

So in short.... if you are updating anything but the sync flag then set the sync flag to NULL. If the only update you are doing it to set sync = 'y' then allow this.

Cheers,
Adam

Options: ReplyQuote


Subject
Views
Written By
Posted
Never used triggers before - please help!
2069
October 02, 2006 03:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.