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;
相关推荐
Elastic 中国社区官方博客18 分钟前
使用 cloud-native Elasticsearch 与 ECK 运行
大数据·数据库·elasticsearch·搜索引擎·kubernetes·k8s·全文检索
Mr_hwt_12330 分钟前
基于MyCat 中间件实现mysql集群读写分离与从库负载均衡教程(详细案例教程)
数据库·mysql·中间件·mysql集群
酷ku的森1 小时前
Redis中的Zset数据类型
数据库·redis·缓存
zhong liu bin1 小时前
MySQL数据库面试题整理
数据结构·数据库·mysql
luckys.one6 小时前
第9篇:Freqtrade量化交易之config.json 基础入门与初始化
javascript·数据库·python·mysql·算法·json·区块链
言之。7 小时前
Django中的软删除
数据库·django·sqlite
阿里嘎多哈基米9 小时前
SQL 层面行转列
数据库·sql·状态模式·mapper·行转列
抠脚学代码9 小时前
Ubuntu Qt x64平台搭建 arm64 编译套件
数据库·qt·ubuntu
jakeswang9 小时前
全解MySQL之死锁问题分析、事务隔离与锁机制的底层原理剖析
数据库·mysql
Heliotrope_Sun10 小时前
Redis
数据库·redis·缓存