I have to create a trigger in a table proyect, to check if all the tests for the proyect are 'ready'. If all of them are ready, I need to search the proyect and put the status of the proyect as 'ready'. If not, Incomplete.
I'm aware that I need to create one trigger for the UPDATE, and another one for the INSERT. I've planned something like this, But I can not make it work.
I created this solution, if the total number of test for that proyect, is below to the number of test ready for that proyect, then the proyect is not ready. and if both are equals, the proyect is ready.
I don't know why it doesn't work:
CREATE TRIGGER update-proyect
AFTER INSERT ON tests
FOR EACH ROW
SET @total = select COUNT(*)
from tests
where IdProyect= NEW.IdProyect;
SET @ready = select COUNT(*)
from prueba
from tests
where IdProyect= NEW.IdProyect
AND status = 'ready';
IF (@total == @ready)
UPDATE proyect SET status = 'Ready' WHERE IdProyect = NEW.IdProyect;
ELSE
UPDATE proyect SET status = 'Incomplete' WHERE IdProyect = NEW.IdProyect;
END IF;