1

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

Alexander Lomov
  • 119
  • 1
  • 5

2 Answers2

2

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.

Trigger Syntax and Examples

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
1

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;

Community
  • 1
  • 1
lopushen
  • 1,117
  • 2
  • 11
  • 32