I have a multiple table database. I need to have 1 table that keeps track of 4 of the child tables. The structure of the 4 child tables is as follows.
table1-4
id = auto_increment
masterid = (Needs to be the ID of the master table)
more fields...
The master table is
id = auto_increment
tablesid = The id of the table depending on which table gets a insert.
The trigger is this
DELIMITER $$
CREATE TRIGGER ins_masterid AFTER INSERT ON `table1`
FOR EACH ROW BEGIN
INSERT INTO mastertable (id, table1id) VALUES (NULL, NEW.id);
SET NEW.table1id = LAST_INSERT_ID();
END$$
DELIMITER ;
The trigger is created and runs with INSERTS, but the table1id is not inserted into the mastertable. On every insert the value is 0. Apparently NEW.id in the INSERT INTO line is not the right thing to use. This is my first go at triggers, so any help would be greatly appreciated.