3
DELIMITER $$

CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER `ir_db1407`.`after_update_ind_user` AFTER UPDATE
ON `ir_db1407`.`ind_user`
FOR EACH ROW BEGIN
SET @user_id=OLD.id
IF (NEW.STATUS = '2' OR NEW.STATUS ='3') 
THEN 
 DELETE FROM ind_user_events WHERE user_id = @user_id;
 DELETE FROM ind_user_mobile WHERE user_id = @user_id;
END IF;
END$$

DELIMITER;

错误代码:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'if (new.status = '2' or new.status ='3') 附近使用正确的语法,然后在第 7 行从 ind_user_events wh' 中删除

4

1 回答 1

2

改变

SET @user_id=OLD.id

SET @user_id=OLD.id;
                   ^

你实际上甚至不需要这个变量。所以放弃那条线并尝试

...
IF (NEW.STATUS = '2' OR NEW.STATUS ='3') THEN 
  DELETE FROM ind_user_events WHERE user_id = OLD.id;
  DELETE FROM ind_user_mobile WHERE user_id = OLD.id;
END IF;
...
于 2013-05-24T06:44:44.027 回答