DELIMITER //
CREATE TRIGGER auto_join
AFTER INSERT ON taiwan_cain.charac_stat
FOR EACH ROW
BEGIN
DECLARE v_m_id INT;
DECLARE v_charac_no INT;
DECLARE v_charac_name VARCHAR(255);
DECLARE v_lev INT;
DECLARE v_job INT;
DECLARE v_grow_type INT;
DECLARE v_current_time DATETIME;
-- 更新 charac_info 表的 guild_id 和 guild_right
UPDATE taiwan_cain.charac_info
SET guild_id = 4, guild_right = 1
WHERE charac_no = NEW.charac_no;
-- 获取新插入的角色信息
SELECT m_id, charac_no, charac_name, lev, job, grow_type, NOW() INTO v_m_id, v_charac_no, v_charac_name, v_lev, v_job, v_grow_type, v_current_time
FROM taiwan_cain.charac_info
WHERE charac_no = NEW.charac_no;
-- 插入新成员到 guild_member 表
INSERT INTO d_guild.guild_member
(guild_id, m_id, server_id, charac_no, charac_name, memo, grade, job, grow_type, lev, member_time, member_flag, last_play_time, age, born_year)
VALUES
(4, v_m_id, 3, v_charac_no, v_charac_name, 'Tender Feelings', 3, v_job, v_grow_type, v_lev, v_current_time, 1, v_current_time, 0, '00');
-- 更新 guild_info 表的 member_count
UPDATE d_guild.guild_info
SET member_count = member_count + 1
WHERE guild_id = 4;
END //
DELIMITER ;