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;//
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;//
...全文
相关推荐
MySQL触发器 Update触发Insert失败
主要介绍了MySQL触发器 Update触发Insert失败 的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下
mysql中经典的触发器语法及相关配置
mysql中经典的触发器语法及相关配置
mysql触发器及相关代码示例
mysql触发器及相关代码示例
Mysql导出存储过程.docx
。。。
MySQL初识与创建数据库[项目源码]
本文介绍了在MySQL数据库中创建数据库的基本步骤。通过进入指定目录并编辑TestDb.sh文件,用户可以执行创建数据库的操作。文章还提到,如果未出现预期结果,可以联系作者进行答疑。作者自称是头歌闯关王,涉猎头歌7千多关,对于其他关卡的问题也可以提供帮助。


