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;
相关推荐
流星白龙5 小时前
【Redis】2.Redis重大版本
数据库·redis·junit
流星白龙5 小时前
【Redis】7.Hash表
数据库·redis·哈希算法
流星白龙5 小时前
【Redis】4.基本全局命令
数据库·redis·缓存
王八八。6 小时前
Navicat 17破解版下载安装教程 附安装激活步骤(2026 最新版)
数据库·navicat
Jelena157795857927 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
流星白龙9 小时前
【Redis】3.Redis安装与命令行客户端
数据库·redis·缓存
二宝哥9 小时前
MySQL 修改密码策略详解:从基础到高级配置
mysql·密码学
马优晨9 小时前
DBeaver 连接 MySQL 完整排错教程
mysql·dbeaver连接mysql·dbeaver连mysql·dbeaver连接数据库·db连接mysql
凌虚10 小时前
基于 PostgreSQL WAL 构建 CDC 系统:原理与工程实现
数据库·后端·postgresql
BullSmall10 小时前
PostgreSQL 14 pg_dumpall 完整备份指南
数据库·postgresql·oracle