×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

After Update Trigger?

After Update Trigger?

After Update Trigger?

(OP)
I'm trying to use an After Update trigger to compare two column in my table (custom_avail_history) and if they do not match, insert the record into another table (custom_avail_history_changelog) to track changes over time. When I try using the code below it tells me "ERROR 1054: 1054: Unknown column 'cah_avail' in 'field list'" 'cah_avail' is a column in the table being updated and i've check the spelling and there are no extra spaces or anything like that. I'm new to using triggers so my code may be way off. If someone could point me in the right direction, I would greatly appreciate it. Thanks


CODE

CREATE DEFINER=`user123`@`%` TRIGGER `import`.`custom_avail_history_AFTER_UPDATE` AFTER UPDATE ON `custom_avail_history` FOR EACH ROW
BEGIN
IF (cah_avail <> cah_prevail) then
INSERT INTO custom_avail_history_changelog (cahc_variety, cahc_avail, cahc_prevail) VALUES (cah_variety, cah_avail, 
cah_prevail);
End if;
END 

RE: After Update Trigger?

Your trigger is an On Update Trigger, so your trigger has access to 2 possible values for cah_avail (and every other value for each of the columns), the OLD one and the NEW one (even if you didn't change it and they remain the same value). You have to preface the column name with either OLD.cah_avail or NEW.cah_avail, letting MySQL know which of the 2 you want.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close