这里就是我想要做的事:MySQL的 - 触发用于插入后更新同桌
当有一个新的INSERT
到表ACCOUNTS
,我需要通过设置status='E'
更新的行中ACCOUNTS
其中pk
= NEW.edit_on
表示特定(旧)帐户已被编辑。
DELIMITER $$
DROP TRIGGER IF EXISTS `setEditStatus`$$
CREATE TRIGGER `setEditStatus` AFTER INSERT on ACCOUNTS
FOR EACH ROW BEGIN
update ACCOUNTS set status='E' where ACCOUNTS.pk = NEW.edit_on ;
END$$
DELIMITER ;
的要求是不是我操纵新插入列,但一个已有柱pk = NEW.edit_on
但是,我不能更新同一表:Can't update table ACCOUNTS ... already used by the statement that invoked this trigger
请建议一种解决方法
PS:我有一个已经通过Updating table in trigger after update on the same table,Insert into same table trigger mysql,Update with after insert trigger on same table和mysql trigger with insert and update after insert on table,但他们似乎不回答我的问题。
编辑
ACCOUNTS
表:
CREATE TABLE `ACCOUNTS` (
`pk` bigint(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(9) unsigned NOT NULL,
`edit_on` bigint(10) unsigned DEFAULT NULL,
`status` varchar(1) NOT NULL DEFAULT 'A',
PRIMARY KEY (`pk`) USING BTREE) ENGINE=InnoDB AUTO_INCREMENT=2147483726 DEFAULT CHARSET=latin1
如何唯一标识'ACCOUNTS'中的行?如果'edit_on'是您的主键,那么您如何插入重复项? – pjama
我编辑了这个问题来包含表结构。请参见。 – th3an0maly
如果'edit_on = 123'表示'pk = 456'的行,这意味着'456'是'123'上的编辑。因此,'status'应该更新为''E'''123' – th3an0maly