I know there must be a simple way to do this but I couldn't find one. I want to create a trigger that basically, when a row is created in table1, creates a n开发者_如何学编程ew row in table2 with a foreign key of the id of table1. what is the general syntax for this? thanks!!
CREATE TRIGGER Syntax
For example -
DELIMITER $$
CREATE TRIGGER trigger1
AFTER INSERT
ON table1
FOR EACH ROW
BEGIN
INSERT INTO table2(id) VALUES(NEW.id);
END$$
DELIMITER ;
something like this:
CREATE TRIGGER `create_t1` AFTER INSERT ON `table1` FOR EACH ROW BEGIN
INSERT INTO table2
SET t1ID = NEW.ID,
when = Now();
END;
精彩评论