欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql触发器的编写

程序员文章站 2022-06-04 08:46:06
...
DROP TABLE IF EXISTS `tb_pf_department`;
CREATE TABLE `tb_pf_department` (
  `dept_idd` int(11) NOT NULL AUTO_INCREMENT,
  `parent_idd` int(11) DEFAULT NULL,
  `deptt_name` varchar(50) DEFAULT NULL,
  `typee` int(2) DEFAULT NULL,
  `sort_noo` int(11) DEFAULT NULL COMMENT '显示顺序',
  `remark` varchar(200) DEFAULT NULL,
  `updated` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `created` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`dept_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=394 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='部门表';
DROP TRIGGER IF EXISTS `tri_tb_pf_department_insert`;
DELIMITER ;;
CREATE TRIGGER `tri_tb_pf_department_insert` AFTER INSERT ON `tb_pf_department` FOR EACH ROW BEGIN
  delete from tb_pf_department_hierarchical;
	INSERT INTO tb_pf_department_hierarchical (`dept_id`, `dept_name`,create_time) 
	select dept_id,dept_name,CURRENT_TIMESTAMP from view_deptment_hierarchical;
  
  
END
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `tri_tb_pf_department_update`;
DELIMITER ;;
CREATE TRIGGER `tri_tb_pf_department_update` AFTER UPDATE ON `tb_pf_department` FOR EACH ROW BEGIN
  delete from tb_pf_department_hierarchical;
	INSERT INTO tb_pf_department_hierarchical (`dept_id`, `dept_name`,create_time) 
	select dept_id,dept_name,CURRENT_TIMESTAMP from view_deptment_hierarchical;
  
  
END
;;
DELIMITER ;

 

相关标签: mysql 触发器