MySQL Forums
Forum List  »  Triggers

Re: Dynamically Referencing OLD/NEW values?
Posted by: Imran Akbar
Date: February 06, 2013 01:45PM

I was having the same issue - I'd like to be able to have the trigger insert into another table the values from the NEW row that was inserted into the table I'm triggering on.
It only works if I hard-code in the column names, so I can't use variables declared like this inside an insert statement:

SET @new_column = CONCAT("NEW.",@column);
which is because of the restriction on dynamic SQL inside the trigger.

Are there any other ways to accomplish this sort of thing inside a trigger?

Perhaps if the trigger is after the insert, get the LAST_INSERT_ID and then:
SELECT @column_name INTO @data FROM your_table WHERE id=@last_insert_id;
and then you could insert @data into your other table?

thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Dynamically Referencing OLD/NEW values?
3814
February 06, 2013 01:45PM


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.