欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

触发器的应用

程序员文章站 2022-05-29 11:37:42
DROP TRIGGER IF EXISTS act_no_desc;CREATE TRIGGER act_no_descAFTER INSERT ON activity20180914_log FOR EACH ROWBEGIN if new.desctription is NULL THEN I ......


drop trigger if exists act_no_desc;
create trigger act_no_desc
after insert on activity20180914_log for each row
begin
if new.desctription is null then
insert into act_error (table_name, error_id, desc_error, error_time)
values ('topic.activity_20180914_log',new.id,'缺少desc',new.create_time);
end if;
end;

drop trigger if exists act_no_desc2;
create trigger act_no_desc2
after update on activity20180914_log for each row
begin
if new.desctription is null then
insert into act_error (table_name, error_id, desc_error, error_time)
values ('tapic.activity_20180914_log',new.id, '缺少desc2', new.create_time);
end if;
end;


drop table if exists act_error;
create table act_error (
id int unsigned auto_increment comment 'id',
table_name varchar(64) not null comment '表名',
error_id int unsigned not null comment '错误的id',
desc_error varchar(64) not null default 'no desc' comment '简介',
error_time timestamp not null default current_timestamp comment '时间',
primary key (id)
)engine = innodb default charset=utf8 comment 'error记录';

insert into activity20180914_log (userid,activity_id,desctription) values
(999,101,'这是错误');

update activity20180914_log set userid=9,desctription=null
where id=8292;