创建状态为带有状态为2的触发器,并且我需要在del_status = 2时第二次更新行之后创建一个老虎机
CREATE TRIGGER `exchange_log_update` AFTER UPDATE ON `exchange`
FOR EACH ROW INSERT
IF NEW.del_status = 2
INTO
exchange_log
SET
client_id = NEW.client_id,
ex_type = NEW.ex_type,
segment_type = NEW.segment_type,
validity_from = NEW.validity_from,
validity_to = NEW.validity_to,
file_upload = NEW.file_upload,
log_status = 'update',
created_at = NEW.created_at
END IF
END
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF NEW.del_status
INTO
exchange_log
SET
client_id = NEW.client_id,
ex' at line 3
答案 0 :(得分:4)
尝试
CREATE TRIGGER `exchange_log_update_new` AFTER UPDATE ON `exchange`
FOR EACH ROW BEGIN
IF (NEW.del_status = 2)
THEN
INSERT INTO `exchange_log`
values(client_id = NEW.client_id,
ex_type = NEW.ex_type,
segment_type = NEW.segment_type,
validity_from = NEW.validity_from,
validity_to = NEW.validity_to,
file_upload = NEW.file_upload,
log_status = 'update',
created_at = NEW.created_at);
END IF;
END