简体   繁体   English

在第三个表上插入后,触发为在另一个表中的每一行的表中插入元组

[英]Trigger to insert tupples to a table for each row in another table after insert on a third table

I have three table council_member, mess and rates. 我有三个表Council_member,混乱和费率。

council_member(student_id, field2,...)
mess(mess_id,field2,...)
rates(student_id,mess_id,rating)

student_id and mess_id are foreign keys. student_id和mess_id是外键。

Rates stores the rating for each mess by each council member. 费率存储每个理事会成员对每个混乱的评级。 I want to create a trigger that on insertion of a new council member, inserts tupples to the table rates for the inserted student_id and each mess_id in mess with a rating of 10. 我想创建一个触发器,该触发器在插入新的理事会成员时将tupples插入插入的student_id和每个mess_id的表费率中,评分为10。

How do I run the insert statement in trigger for each mess_id? 如何在触发器中为每个mess_id运行insert语句?

This works great 这很棒

CREATE TRIGGER insert_council_member 
AFTER INSERT ON council_member
FOR EACH ROW 
  INSERT INTO rates SELECT NEW.student_id, mess_id, 10 FROM mess;

http://sqlfiddle.com/#!2/ac4a0/1 http://sqlfiddle.com/#!2/ac4a0/1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM