Mysql5.7.21 Navicat触发器创建
程序员文章站
2022-08-31 12:48:13
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;
上一篇: 学习笔记—MySQL基础