MySQL Forums
Forum List  »  Triggers

MySql update trigger works sporatically
Posted by: Buck Powell
Date: August 29, 2013 09:21AM

I have mysql v5.x installed on a windows webserver. I have 4 fields that have to be updated based on changes to 4 different fields:

status - status_date
priortity - priority_date
analysis notes - analysis_note_date
assigned_user_id - assigned_date

As an example, when status is changed, it should update the status_date field.

All fields except analysis_notes are varchar(100) and they are rendered as dropdowns.

The analysis_note field is a text field. This is one that does work all the time. Sometimes it updates, sometimes it doesnt.

I am posting my scripts in hopes of someone finding a solution.

create trigger t_u_dates
before update
on cases
for each row
begin
IF (NEW.status <> OLD.status) THEN
SET NEW.status_date = Now();
ELSE
SET NEW.status_date = OLD.status_date;
END IF;

IF (NEW.priority <> OLD.priority) THEN
SET NEW.priority_date = Now();
ELSE
SET NEW.priority_date = OLD.priority_date;
END IF;

IF (NEW.assigned_user_id <> OLD.assigned_user_id) THEN
SET NEW.assigned_date = Now();
ELSE
SET NEW.assigned_date = OLD.assigned_date;
END IF;

IF (OLD.analysis_notes <> NEW.analysis_notes) THEN
SET NEW.analysis_note_date = Now();
ELSE
SET NEW.analysis_note_date = OLD.analysis_note_date;
END IF;

end;//

Options: ReplyQuote


Subject
Views
Written By
Posted
MySql update trigger works sporatically
1568
August 29, 2013 09:21AM


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.