当前位置: 移动技术网 > IT编程>数据库>Mysql > 触发器的应用

触发器的应用

2018年10月11日  | 移动技术网IT编程  | 我要评论


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;

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

相关文章:

验证码:
移动技术网