当前位置:网站首页>[MySQL learning notes 29] trigger

[MySQL learning notes 29] trigger

2022-07-06 07:19:00 yqs_ two hundred and eighty-one million eight hundred and seven

establish

CREATE TRIGGER trigger_name
BEFORE/AFTER INSERT/UPDATE/DELETE
ON tb_name FOR EACH ROW – Line level triggers
BEGIN
trigger_statement;
END;

see

SHOW TRIGGERS;

Delete

DROP TRIGGER [schema_name.]trigger_name; -- Is not specified schema_name The default is the current database

Case study

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(' The inserted data content is :',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(' Data before updating :',old.content));
end;
原网站

版权声明
本文为[yqs_ two hundred and eighty-one million eight hundred and seven]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060713326683.html