触发器的应用
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;
上一篇: WCF(三)分布式事务