[英]sql- get data from one table to insert into another in a trigger
I have a trigger and I need to insert the ID from the tracks able into the events table AFTER insert into tracks. 我有一个触发器,在插入轨道后,我需要将轨道中的ID插入事件表中。 I just need to select the ID from tracks, nothing more.
我只需要从曲目中选择ID,仅此而已。 The ID in the tracks table has a foreign key to the ID in another table named members.
轨道表中的ID对另一个名为成员的表中的ID具有外键。 I doubt that is important but just in case.
我怀疑这是否重要,但以防万一。 I shouldn't imagine you need any info on the tables but just ask if you do.
我不应该想象您需要桌上的任何信息,而只是问您是否需要。
Here is my trigger 这是我的触发器
delimiter $$
CREATE
TRIGGER tracks_event AFTER INSERT
ON tracks FOR EACH ROW
BEGIN
INSERT into events(ID, action)
VALUES (?, has uploaded a track.);
END$$
delimiter ;
If you want the ID that is in the tracks row being inserted then you can use NEW.ID
. 如果要插入轨道行中的ID,则可以使用
NEW.ID
This will give you this ID column of the row that has been inserted. 这将为您提供已插入行的此ID列。
For more trigger examples and a few hints the MySQL reference manual helps (along with being a great reference for syntax etc): http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html 有关更多触发器示例和一些提示,MySQL参考手册会有所帮助(以及有关语法等的大量参考): http : //dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.