Dusty
asked on
MySQL Update Trigger question
I want to track latest Price change for an item.
The table name is res, field names are price, prevprice, priceupdatedate
I need help with writing a trigger that updates the field "prevprice" with the old price when the "price" field is updated and then writes the current time stamp to the priceupdatedate field.
code example appreciated! Thanks!
The table name is res, field names are price, prevprice, priceupdatedate
I need help with writing a trigger that updates the field "prevprice" with the old price when the "price" field is updated and then writes the current time stamp to the priceupdatedate field.
code example appreciated! Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@ChrisStanyon
Thanks for the help!
Running the trigger did work for the setting the NEW.prevprice = OLD.price
The priceupdateddate column I changed to timestamp but it did not update the field when updating the price.
I tried:
SET NEW.prevprice = OLD.price, priceupdatedate = NOW();
but that didn't work either says my version of MySQL doesnt support multiple triggers with same action time and event for one table.
Thanks for the help!
Running the trigger did work for the setting the NEW.prevprice = OLD.price
The priceupdateddate column I changed to timestamp but it did not update the field when updating the price.
I tried:
SET NEW.prevprice = OLD.price, priceupdatedate = NOW();
but that didn't work either says my version of MySQL doesnt support multiple triggers with same action time and event for one table.
if you edit the trigger using the code I provided it will try and create the same trigger again so you need to delete it first. the timestamp column should update automatically but only if it's the only timestamp column in your table. that may depend on your version of mysql
ASKER
Works perfect!
Thanks so much!
Thanks so much!
http://dev.mysql.com/doc/refman/5.5/en/trigger-syntax.html