0

我有两个表名:registeredList 和 deregisteredlist。现在,当用户从“registeredlist”表中注销时,触发器会将他的信息更新到注销表并从注册表中删除记录。在我下面的过程中,我可以正确更新它,但不能从注册表中删除用户。我的过程:

DELIMITER $$
USE `abc_db`$$
DROP TRIGGER  `UnsubscriberListTrigger`$$
CREATE        
    TRIGGER `UnsubscriberListTrigger` AFTER UPDATE ON `registeredlist` FOR EACH ROW 
    BEGIN        
     IF (old.SubscriberStatus='registered') THEN    
       INSERT INTO deregisteredlist(name,SubscriberStatus,DeRegistrationDate) 
       VALUES(old.name,'Deregistered',NOW());

       DELETE from registeredlist where old.id=new.id;/???????/I am getting problem here           
     END IF;
 END $$
DELIMITER ;

提前致谢。

4

2 回答 2

2

我认为你需要的只是改变WHERE陈述DELETE。它应该是这样的:

DELETE from registeredlist where id=old.id; // (or new.id cause in this case old.id is equal to new.id)

...因为您想将其与id列匹配。

更新:

另一种可能性是: - 创建 AFTER INSERT TRIGGER 将在deregisteredlist其上执行删除registeredlist。这样你就不应该得到那个错误。

于 2012-12-04T13:56:57.643 回答
0

试试这个::

DELETE from registeredlist order by updateddat desc limit 1;
于 2012-12-04T13:56:32.387 回答