mysql触发器 if条件判断

下面是一段带条件判断的触发器

sql 复制代码
CREATE TRIGGER `check_users` BEFORE INSERT ON `mk_mm_marketparticipant`
FOR EACH ROW
BEGIN
    IF NEW.exchange_code = '02' THEN
        	insert into mk_td_base_participant_02(
						participant_id,
						participant_name,
						participant_short_name,
						participant_type,
						participant_code,
						exchange_code,
						file_type,
						file_sync_time
					) values (NEW.participant_id, NEW.participant_name, NEW.participant_short_name, NEW.participant_type, NEW.participant_code, NEW.exchange_code, '01', DATE_FORMAT(NOW(), '%Y-%m-%d'));

    END IF;

    IF NEW.exchange_code = '03' THEN
        	insert into mk_td_base_participant_03(
						participant_id,
						participant_name,
						participant_short_name,
						participant_type,
						participant_code,
						exchange_code,
						file_type,
						file_sync_time
					) values (NEW.participant_id, NEW.participant_name, NEW.participant_short_name, NEW.participant_type, NEW.participant_code, NEW.exchange_code, '01', DATE_FORMAT(NOW(), '%Y-%m-%d'));

    END IF;
	
	IF NEW.exchange_code = '04' THEN
        	insert into mk_td_base_participant_04(
						participant_id,
						participant_name,
						participant_short_name,
						participant_type,
						participant_code,
						exchange_code,
						file_type,
						file_sync_time
					) values (NEW.participant_id, NEW.participant_name, NEW.participant_short_name, NEW.participant_type, NEW.participant_code, NEW.exchange_code, '01', DATE_FORMAT(NOW(), '%Y-%m-%d'));

    END IF;
	
	
END;
相关推荐
lllsure13 小时前
【MySQL】数据分片
数据库·mysql
语落心生13 小时前
深入doris查询计划以及io调度(五)列式存储结构 - 分析Segment格式、列数据编码
数据库
DBA小马哥13 小时前
金仓数据库 vs 达梦:MySQL迁移谁更胜一筹?
数据库·mysql·金仓数据库·kes
Luna-player14 小时前
那个在DG数据库中将多行指定字段的文本替换操作
数据库
それども14 小时前
MySQL 执行计划中 filtered = 100 是什么意思
数据库·mysql
技术净胜14 小时前
Python 连接 MySQL 数据库步骤
数据库·python·mysql
厦门辰迈智慧科技有限公司14 小时前
城市地下管网全域监测与安全防控整体解决方案
数据库·安全·物联网解决方案·地下管网监测·城市地下管网监测
小肖爱笑不爱笑14 小时前
JDBC Mybatis
数据库·mybatis
cookqq15 小时前
MySQL 5.7 大表删除部分数据:.ibd 文件会变小吗?磁盘会释放吗?
数据结构·数据库·mysql
IT 行者15 小时前
告别硬编码!Spring Boot 优雅实现 Controller 路径前缀统一管理
数据库·spring boot·python