Mysql5.7.21 Navicat触发器创建
程序员文章站
2022-05-14 18:22:01
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 ......
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;
上一篇: jquery中的ajax方法怎样通过JSONP进行远程调用
下一篇: nginx网站标准配置