createtrigger emp_logs_insert_trigger after insert on emp foreachrow begin insertinto emp_logs (id,operation,operate_time,operate_id,operate_params) values(null,'insert',now(),new.id, concat('插入后(id:',new.id,', name:',new.name,', age:',new.age,',salary:',new.salary,')') ); end$
创建 update 型触发器,完成更新数据时的日志记录 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
createtrigger emp_logs_update_trigger after update on emp foreachrow begin insertinto emp_logs (id,operation,operate_time,operate_id,operate_params) values(null,'update',now(),new.id, concat( '修改前(id:',old.id,', name:',old.name,', age:',old.age,', salary:',old.salary,') , 修改后(id',new.id, 'name:',new.name,', age:',new.age,', salary:',new.salary,')' ) ); end$
创建delete 行的触发器 , 完成删除数据时的日志记录 :
1 2 3 4 5 6 7 8 9 10 11
createtrigger emp_logs_delete_trigger after delete on emp foreachrow begin insertinto emp_logs (id,operation,operate_time,operate_id,operate_params) values(null,'delete',now(),old.id, concat('删除前(id:',old.id,', name:',old.name,', age:',old.age,', salary:',old.salary,')') ); end $