关于mysql触发器问题 表(testT)定义: id int version int name string 建立触发器,更新时自动算出最大的version,并赋值给当前修改行的version字段。
下面写法不对,求修改以及其他简单写法 create trigger t_updateVersion before update on testT for each row begin declare aaa INT; /*出错:sql syntax error near INT*/ select aaa= max(version) from testT; set new.version = aaa + 1; end /*出错:sql syntax error near INT*/
------解决方案--------------------
SQL code
delimiter //
create trigger t_updateVersion
before update on testT
for each row
begin
declare aaa int;
select max(version) into aaa from testT;
set new.version = aaa + 1;
end;//
------解决方案--------------------