I have a table SCHEDULES_CLASS
, 2 of it's fields are CLASS_ID
(foreign key from the CLASS table), STATUS
and NUMBER_OF_ENROLLED_STUDENTS
. I have other table CLASS
having 1 field as MAX_SEATS.
When the NUMBER_OF_ENROLLED_STUDENTS
in a scheduled class equals the MAX_SEATS
available for the respective CLASS, I need to change the status of that SCHEDULES_CLASS
to "FULL" from the initial status which is "OPEN".
I created a trigger for this purpose as follows:
USE mydb;
DELIMITER ##
dROP TRIGGER IF EXISTS updateClassStatusTrigger ##
CREATE TRIGGER updateClassStatusTrigger
BEFORE UPDATE ON SCHEDULED_CLASS
FOR EACH ROW
BEGIN
UPDATE SCHEDULED_CLASS SET STATUS="FULL" WHERE CLASS_ID=NEW.CLASS_ID
AND EXISTS (SELECT 1 FROM SCHEDULED_CLASS sc, CLASS cl WHERE cl.CLASS_ID=NEW.CLASS_ID AND NEW.NUMBER_OF_ENROLLED_STUDENTS=cl.MAX_SEATS);
END##
I am using phpmyadmin, and I get the following error, when any update takes place on the SCHEDULED_CLASS table:
#1442 - Can't update table 'SCHEDULED_CLASS' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Any ideas, how to accomplish this task? i.e. update the status of the scheduled class to 'FULL' whenever the enrolled students number reaches the max available seats.
Thanks