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;
相关推荐
一 乐1 小时前
智慧党建|党务学习|基于SprinBoot+vue的智慧党建学习平台(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·学习
许愿OvO2 小时前
MySQL触发器
android·mysql·adb
lcanfly3 小时前
Mysql作业4
数据库·mysql
蓝象_3 小时前
docker安装配置mysql
mysql·docker·容器
喜欢踢足球的老罗3 小时前
认证与授权:详解大型系统中用户中心与RBAC的共生关系
数据库·rbac
zhaomx19893 小时前
Spring 事务管理 Transaction rolled back because it has been marked as rollback-only
数据库·spring
l1t5 小时前
利用DeepSeek优化SQLite求解数独SQL用于DuckDB
开发语言·数据库·sql·sqlite·duckdb
lcanfly5 小时前
Mysql作业5
android·数据库·mysql
rit84324995 小时前
在Ubuntu上配置Nginx实现开机自启功能
数据库·nginx·ubuntu