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 8478749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:49:56+00:00 2026-06-10T18:49:56+00:00

Basically i’m going to run this procedure anytime a student enrolls/drops a course. I’m

  • 0

Basically i’m going to run this procedure anytime a student enrolls/drops a course.
I’m trying to set student_total = # of students in a course, then update that corresponding section with (student_total + 1) i’m having trouble finding good documentation for stored procedures. I’m getting an error on my Declare student_total int; line. What am i not doing correct?

DELIMITER $$

CREATE PROCEDURE `mydb`.`update_seats` (IN section_ID varchar(20))
BEGIN

SET @section_id=section_id;

DECLARE student_total int;
-- count the number of students in the course --

SET student_total = SELECT count(student_ID) from course
WHERE section_ID = @section_id;


Update Section SET students_enrolled = (student_total + 1) 
WHERE section_ID = @section_id;




END
  • 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-10T18:49:58+00:00Added an answer on June 10, 2026 at 6:49 pm

    Problems

    Error 1

    From MySql documentation:

    DECLARE is permitted only inside a BEGIN … END compound statement and must be at its start, before any other statements.

    So, you should move DECLARE... statement before the SET @section_id... statement.

    Error 2

    You are trying to select a value into a variable using invalid snytax! You should use SELECT ... INTO instead of SET ... = SELECT ... (which is invalid syntax).

    Removing Redundancy

    No need to assign parameter (section_ID) to a global variable (@section_ID). You can simply change the parameter name to avoid name collision with section.section_ID column.

    Solution

    DELIMITER ;;
    
    CREATE PROCEDURE `update_seats` (IN p_section_ID VARCHAR(20))
    BEGIN
        DECLARE student_total INT;
    
        SELECT  count(student_ID)
        INTO    student_total
        FROM    course
        WHERE   section_ID = p_section_ID;
    
        UPDATE  section
        SET     students_enrolled = (student_total + 1)
        WHERE   section_ID = p_section_ID;
    END;;
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a large set of data in excel, and I was wondering
Basically, I have a list of delivery checkboxes one for deliver to this address
Basically, what I'm trying to create is a page of div tags, each has
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I'm attempting to add rows to a table, I need to do this
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically this function is meant to store the height value of the element that
Basically my question is, if I have a number string, and i'm going to
Basically I need to be able to do this: var obj = {foo:bar}, arr
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.

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.