MySQL Forums
Forum List  »  French

Récupération d'un numéro auto incrémenté dans un trigger
Posted by: Jean-Marie DUCHESNE
Date: December 09, 2013 04:06PM

Bonjour,

J'ai une table 'action' suivant le code SQL suivant :

CREATE TABLE IF NOT EXISTS `gestion`.`action` (
`act_id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`act_action_origine` INT UNSIGNED NULL,
`act_detail` TEXT NULL,
PRIMARY KEY (`act_id`),
INDEX `fk_action_action_idx` (`act_action_origine` ASC),
CONSTRAINT `fk_action_action`
FOREIGN KEY (`act_action_origine`)
REFERENCES `gestion`.`action` (`act_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB

Je souhaiterais créer un trigger AFTER INSERT me permettant de récupérer la valeur de 'act_id' pour la copier dans 'act_action_origine' lorsque 'act_action_origine' est NULL ce qui devrait ressembler à qualque chose comme ça :

CREATE TRIGGER `action_AINS` AFTER INSERT ON `action` FOR EACH ROW
begin
if(new.act_action_origine is null) then
set new.act_action_origine = 1;
end if;
end

Le problème c'est que ce ne marche pas car j'ai l'erreur suivante :

ERROR: Error 1362: Updating of NEW row is not allowed in after trigger

Avez-vous une idée pour contourner cette erreur?
Merci d'avance.

Options: ReplyQuote


Subject
Views
Written By
Posted
Récupération d'un numéro auto incrémenté dans un trigger
2957
December 09, 2013 04:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.