mysql触发器创建报错

ssdduy ssdduy 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有两个表:table1、table2,当table1更新时触发更新tables2
delimiter //
create trigger table1_update AFTER update on table1 for each row
BEGIN
declare sum1,sum2 int default 0;
select sum(col1) into sum1,sum(col2) into sum2 from table1 where sort=NEW.sort;
update tables2 set col1=sum1,col2=sum2 where sort=NEW.sort;
END;//

创建时错误提示:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sum(col2) into sum2 from table1 where sort' at line 4

有试过只操作一个字段,其它不变,就可以正常创建和使用,代码例如:
delimiter //
create trigger table1_update AFTER update on table1 for each row
BEGIN
declare sum2 int default 0;
select sum(col2) into sum2 from table1 where sort=NEW.sort;
update tables2 set col2=sum2 where sort=NEW.sort;
END;//



...全文
评论 1
收藏 已收藏
分享
返回顶部
ssdduy
MySQL 57,062 成员 56,759 内容