我有table1和table2(带外键),请参阅表:
(INSERT INTO table2 (table2.foreignKey) VALUES (table1.id))
答案 0 :(得分:0)
您可以使用Trigger来完成此操作。
它看起来像这样:
delimiter |
CREATE TRIGGER insertIntoTable2 AFTER INSERT ON table1
FOR EACH ROW
BEGIN
INSERT INTO table2 SET foreignKey = NEW.id;
END;
|
delimiter ;