mysql触发器创建报错

ssdduy 2014-01-17 11:20:59
有两个表: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;//



...全文
134 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwwwb 2014-01-17
  • 打赏
  • 举报
回复
select sum(col1),sum(col2) into sum1,sum2 from table1 where sort=NEW.sort;

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧