PHP: CREATE TRIGGER cancella
BEFORE UPDATE ON tipo
FOR EACH ROW
BEGIN
DELETE FROM annunci WHERE tipo_annuncio = OLD.stato LIMIT 1;
DELETE FROM automobile WHERE tipo = OLD.stato LIMIT 1;
END;
Il mio obiettivo è cancellare gli annunci e le automobili quando il tipo cambia stato. Fin qui nessun problema, infatti ogni volta che tipo cambia stato il trigger esegue la sua funzione.
Il problema sta nel fatto che il tipo può assumere tre valori ATTIVO | PRENOTATO | SCADUTO. Il trigger deve eseguire la sua funzione solo quando il tipo diventa SCADUTO.