Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8218455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:47:58+00:00 2026-06-07T12:47:58+00:00

I have a table SCHEDULES_CLASS , 2 of it’s fields are CLASS_ID (foreign key

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:47:59+00:00Added an answer on June 7, 2026 at 12:47 pm

    The way to update same row is to simply SET NEW.column_name = some_Value. To simplify your trigger, consider:

    CREATE TRIGGER updateClassStatusTrigger
    BEFORE UPDATE ON SCHEDULED_CLASS
    FOR EACH ROW
      SET NEW.STATUS='FULL'
    

    Now, in addition, you need only to update value given some condition. This can’t be done within the same query here since we are no longer using a standard UPDATE. So, split:

    USE mydb;
    DELIMITER ##
    dROP TRIGGER IF EXISTS updateClassStatusTrigger ##
    CREATE TRIGGER updateClassStatusTrigger
    BEFORE UPDATE ON SCHEDULED_CLASS
      FOR EACH ROW
      BEGIN
            SELECT 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) INTO @row_exists;
            IF @row_exists THEN
              SET NEW.STATUS='FULL';
            END IF;
      END##
    

    I hope I don’t have some syntax error in the above. I’ve tested it on my own tables, but have then edited to fit your schema.

    Your own attempt failed because from within a trigger, MySQL does not allow you to modify the table from which the trigger executed. It could not analyze your query to determine what you essentially tried can ba accomplished in a valid way – it doesn’t even try. It simply forbids modifying same table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a status field on a class that has an ID and a
I have table with 300 000 records (MyISAM). I get record from this table
I have a php page which displays class schedule data for each user from
I have a table that consists of a unique id, and a few other
I have a structure as <div id =page class=item-page> <table id=schedule> </table> </div> How
I have table named Schedule which has fields named TeacherName and ClassTakenDate.The values in
I have a table of games, which is described as follows: +---------------+-------------+------+-----+---------+----------------+ | Field
I need to create a table to store users' class schedules. These schedules have
I have a table on a page like so: <table id=ctl00_PlaceHolderMain_Table_Name class=schedule-table cellspacing=1 border=0
I have a table similar to the following. <table class=schedule-table cellspacing=1 border=0 style=width:100%;> <tr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.