mysql ------ mysql触发器(增删改)

1.往主表中增加数据

DROP TRIGGER IF EXISTS syn_insert_data;
增加触发器

CREATE TRIGGER syn_insert_data
AFTER INSERT ON dep
FOR EACH ROW
BEGIN
INSERT INTO oper VALUES(new.id,‘i’);
END
2.删除触发器

CREATE TRIGGER syn_delete_data
AFTER DELETE ON dep
FOR EACH ROW
BEGIN
INSERT INTO oper VALUES(old.id,‘d’);
END
3.修改触发器

CREATE TRIGGER syn_update_data
AFTER UPDATE ON dep
FOR EACH ROW
BEGIN
INSERT INTO oper VALUES(old.id,‘u’);
END
查看所有触发器

show triggers;
进行主表增删改会触发事件

你可能感兴趣的:(mysql数据库)