[英]Trigger SQL update on insert
I need some help on creating a trigger on MySQL. 我需要在MySQL上创建触发器的一些帮助。
I have a table "comment": 我有一个表“ comment”:
id_comment | id_topic | comment
and the "topic" table: 和“主题”表:
id_topic | topic | comments_ammount
I need to increase comments_ammount
for each insert on "comment" table which has the same id_topic
of the topic. 我需要增加
comments_ammount
为具有相同的“注释”表中的每个插入id_topic
的话题。
I never used triggers, so anyone can help me? 我从未使用过触发器,所以有人可以帮助我吗?
well ,i am not special in mysql but i think you can do something like this 好吧,我在mysql上不是很特别,但是我认为你可以做这样的事情
DELIMITER $$
declare @x table(id_topic int)
insert into @x '@x hold last insert'
select *
from comment
order by id desc
limit 1
update topic t join @x c
on c.id_topic =t.id_topic
set comments_ammount=comments_ammount+1
DELIMITER $$
DELIMITER ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.