[Cialug] mysql triggers -- figured them out

Kevin C. Smith kevin at linuxsmith.com
Mon Oct 23 11:19:25 CDT 2006


Since I got no response I thought some might be interested in the solution.
After reading the docs it turns out to be fairly simple. Yes, I didn't
read the docs before; I was trying speed it up by getting pointed to
the TIMEDIFF function. To get the time difference of two fields using a
trigger.

CREATE TRIGGER trigger_time BEFORE INSERT ON time_table FOR EACH ROW SET
  NEW.time_diff = TIMEDIFF(NEW.end_time, NEW.begin_time);

Of course an ON UPDATE trigger is also needed.


-- 
Kevin C. Smith



More information about the Cialug mailing list