1.修改数据的触发器
修改数据的触发器
create trigger tb_user_update_trigger
after update on tb_user for each row
begin
insert int user_logs(id,operation,operate_time,operate_id,operate_params)VALUES
(null,'update',now(),new.id,concat
('更新之前的数据:id=',new.id,',name=',new.name,', phone=',new.phone,', email=',new.email,', profession=',new.profession
' | 更新之后的数据:id=',new.id,',name=',new.name,', phone=',new.phone,', email=',new.email,', profession=',new.profession));
end;
show triggers;
更新数据
update tb_user set age = 32 where id = 23;
思考下面这个触发器会触发几次?几条数据就触发几次。
update tb_user set age = 32 where id <= 5;
2.删除数据的触发器
create trigger tb_user_delete_trigger
after delete on tb_user for each row
begin
insert int user_logs(id,operation,operate_time,operate_id,operate_params)VALUES
(null,'delete',now(),old.id,concat
('删除之前的数据:id=',new.id,',name=',new.name,', phone=',new.phone,', email=',new.email,', profession=',new.profession);
end;
show triggers;
文章来源:https://www.toymoban.com/news/detail-610934.html
delete from tb_user where id = 5;
文章来源地址https://www.toymoban.com/news/detail-610934.html
到了这里,关于数据库触发器简介——修改数据的触发器、删除数据的触发器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!