Reputation: 119
I have a trigger which looks like this:
delimiter //
create trigger tracker after insert on Items for each row
begin
end; //
delimiter ;
I need to insert id
, type
, and date_created
of the inserted column to another table as
INSERT INTO Tracker (table_id, type, date) VALUES ( ??? );
I'm not sure how to get those data fields within a trigger. Could someone give me a tip
Upvotes: 1
Views: 386
Reputation: 1137
Use the NEW alias as it is shown in
MySQL trigger On Insert/Update events
As an example CREATE TRIGGER ins_sum BEFORE INSERT ON account FOR EACH ROW SET @sum = @sum + NEW.amount;
Upvotes: 1
Reputation: 64476
You can use NEW.column_name
to get the inserted value within a trigger
INSERT INTO Tracker (table_id, type, date)
VALUES ( NEW.id_col_traker,NEW.col,NEW.col );
Within the trigger body, the OLD and NEW keywords enable you to access columns in the rows affected by a trigger. OLD and NEW are MySQL extensions to triggers; they are not case sensitive.
Upvotes: 2