当前位置:网站首页>【mysql学习笔记29】触发器

【mysql学习笔记29】触发器

2022-07-06 07:13:00 yqs_281876918

创建

CREATE TRIGGER trigger_name
BEFORE/AFTER INSERT/UPDATE/DELETE
ON tb_name FOR EACH ROW – 行级触发器
BEGIN
trigger_statement;
END;

查看

SHOW TRIGGERS;

删除

DROP TRIGGER [schema_name.]trigger_name; --没有指定schema_name默认为当前数据库

案例

create trigger tb_user_insert_trigger after insert on tb_user for each row
begin
	insert into tb_logs(id,operation,operate_time,operate_id,operate_params) 
	values(null,'insert',now(),new.id,concat('插入的数据内容为:',new.content));
end;
create trigger tb_user_insert_trigger after update on tb_user for each row
begin
	insert into tb_logs(id,operation,operate_time,operate_id,operate_params) 
	values(null,'update',now(),new.id,concat('更新前数据:',old.content));
end;
原网站

版权声明
本文为[yqs_281876918]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_31618549/article/details/125546841