mysql触发器创建报错
有两个表: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;//