1.触发器
准备工作:日志表user_logs
create table user_logs(
id int(11) not null auto_increment,
operation varchar(20) not null comment '操作类型', insert/update/delete,
operate_time datetime not null comment '操作时间',
operate_id int(11) not null comment '操作的id',
operate_params varchar(500) not null comment '操作参数',
primary key(`id`)
)engine=innodb default charset=utf8;
插入数据触发器
create trigger tb_user_insert_trigger
after insert on tb_user for each row
begin
insert int user_logs(id,operation,operate_time,operate_id,operate_params)VALUES
(null,'insert',now(),new.id,concat('插入的数据内容为:id=',new.id,',name=',new.name,', phone=',new.phone,', email=',new.email,', profession=',new.profession));
end;
查看触发器的指令
show triggers;
删除指定的触发器
drop trigger tb_user_insert_trigger;
插入数据到tb_user_insert_trigger;
insert int user_logs(id,operation,operate_time,operate_id,operate_params)VALUES
(25,'二皇子','18809091212','erhuangzi@163.com','软件工程',23,'1','1',now());