我在mysql中创建了以下触发器:
DELIMITER $$
CREATE TRIGGER `some_trigger` AFTER INSERT ON db1.table
FOR EACH ROW
BEGIN
IF NEW.userid = 'certain_id' THEN
INSERT INTO db2.table
SET
value1 = NEW.value,
value2 = NEW.value;
END IF;
END $$
DELIMITER ;
如果删除if语句,则上述语句有效。此外,将此触发器添加到db时,不会遇到语法错误。知道if语句有什么问题,当它被添加到db1.table时不允许它在列userid中插入值'certain_id'的条目吗?
答案 0 :(得分:0)
试试这个应该有用..
DELIMITER $$
CREATE TRIGGER `some_trigger` AFTER INSERT ON `db1`.`table`
FOR EACH ROW
BEGIN
IF (NEW.userid = 'certain_id') THEN
INSERT INTO `db2`.`table` (value1, value2)
VALUES (NEW.value1,NEW.value2);
END IF;
END $$
DELIMITER ;