gpt4 book ai didi

mysql - 如何用一个触发器执行多个操作

转载 作者:行者123 更新时间:2023-11-29 07:19:12 24 4
gpt4 key购买 nike

我想将它们合并为一个触发器。我创建第一个查询,然后创建第二个查询。但它说有多个触发器具有相同的 Action 。我的问题是如何将它们结合起来。

 CREATE trigger deletePostsAfterDeleteUser before delete on  
tblusers for each row delete from tblposts where tblposts.userId = old.userId


CREATE trigger deleteReportsAfterDeleteUser before delete on
tblusers for each row delete from tblreports where tblreports.userId = old.userId

最佳答案

使用开始结束:

create trigger deletePostsAfterDeleteUser before delete on  
tblusers
for each row
begin
delete from tblposts where tblposts.userId = old.userId;
delete from tblreports where tblreports.userId = old.userId;
end;

但是,这种类型的操作表明您确实想要 cascading constraints ,而不是触发器。

关于mysql - 如何用一个触发器执行多个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57259963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com