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;
相关推荐
陆少枫10 分钟前
MySQL基础关键_013_常用 DBA 命令
数据库·mysql
赵渝强老师25 分钟前
【赵渝强老师】在PostgreSQL中使用file_fdw访问外部文件系统
数据库·postgresql
Johny_Zhao30 分钟前
K8S+nginx+MYSQL+TOMCAT高可用架构企业自建网站
linux·网络·mysql·nginx·网络安全·信息安全·tomcat·云计算·shell·yum源·系统运维·itsm
智_永无止境38 分钟前
Redis 8.0携新功能,重新开源
数据库·redis·开源
阿乾之铭1 小时前
Spring Boot 参数验证
java·数据库·mysql
唐人街都是苦瓜脸2 小时前
MySQL创建了一个索引表,如何来验证这个索引表是否使用了呢?
数据库·mysql
前进的程序员2 小时前
SQLite 数据库常见问题及解决方法
数据库·sqlite
zhcong_2 小时前
MySQL数据库操作
数据库·mysql
极小狐4 小时前
极狐GitLab 容器镜像仓库功能介绍
java·前端·数据库·npm·gitlab
极小狐4 小时前
如何构建容器镜像并将其推送到极狐GitLab容器镜像库?
开发语言·数据库·机器学习·gitlab·ruby