Mysql 触发器笔记

-- 插入触发器

DELIMITER //
create trigger triggerName <after | before> insert on tableName
FOR EACH ROW
begin
  if
    begin
      -- new.xx, new.xx (可以拿到插入到表tableName的字段值)
    end
  ELSEIF 
    begin
    end   
end;//
DELIMITER ;

-- 更新触发器

DELIMITER //
create trigger triggerName <after | before> update on tableName
FOR EACH ROW
Begin
  -- old.xx 代表更新前字段xx的值
  -- new.xx 代表更新后字段xx的值
END//
DELIMITER ;

-- Delete触发器

DELIMITER //
create trigger triggerName <after | before> delete on tableName
FOR EACH ROW
Begin
  -- old.xx 代表被删除记录字段xx的值
END//
DELIMITER ;

 

posted @ 2021-06-07 09:33  学无止境-小蜗牛  阅读(59)  评论(0编辑  收藏  举报