当前位置: 移动技术网 > IT编程>数据库>Mysql > Mysql5.7.21 Navicat触发器创建

Mysql5.7.21 Navicat触发器创建

2019年03月24日  | 移动技术网IT编程  | 我要评论

create trigger m_trigger after update on table1 
for each row
begin
if( old.status!= new.status)
then
select count(id) from table1 where stats='y' into @ycount;

select max(num) from table2 into @maxycount;
if( @ycount> @maxycount)
then
insert into table2 (num) select count(1) from table1 b where b.statu='y';
end if;
end if;
end

注:mysql中变量不用事先声明,用时直接‘@变量名’使用。

1、set @num=1;  set @num:=1; 

2、select count(id) from table1 where stats='y' into @ycount;

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网