Ciao a tutti,
ho una tabella con tanti test diversi, ma solo uno alla volta puó essere attivo, quindi vorrei che quando l'utente modifica il campo "Active" col valore 1, per gli altri test il valore "Active" vada a 0.
Perció ho fatto questo trigger:
Delimiter //
CREATE TRIGGER Trig_tests
BEFORE UPDATE ON tests
FOR EACH ROW BEGIN
IF New.Active = 1 THEN
update tests set Active = 0 where Test_nbr = OLD.Test_nbr AND Active = 1 AND Test_id != OLD.Test_id;
END IF;
END; //
Delimiter;
Peró quando vado ad aggiornare la tabella mi dice:
Can't update table 'tests' in stored function/trigged cause it is already used by statement which invoked this stored this function/trigger.
Come posso fare?
Grazie
Andrea