Jump to content

Allocating students to courses


sdasilva

Recommended Posts

Hi there,

I have two tables: STUDENT and COURSES.

 

TABLE:STUDENT

Student_Number

FirstName

LastName

CourseName

Course_ID

 

TABLE:COURSES

CourseName

Course_ID

CourseTotalCapacity

CourseCurrentNumberofStudents

 

I want to allocate students to courses,so when I add a student to the student table and allocate him a course,it should also populate the TABLE:COURSES.Meaning each time I add a student to a course the attribute CourseCurrentNumberofStudents on the TABLE:COURSES should increment,but I do not know how to add data to one table and make it populate or update the other table.

Any ideas?

Link to comment
Share on other sites

we can use two insert statements sequentially

 


Insert into STUDENT(col1, col2, col3 etc) values (v1, v2, v3 etc); 

 

Assuming that , you have Primary key on course_id

 


INSERT INTO COURSES (COURSE_ID) VALUES(10)  ON duplicate KEY UPDATE CourseCurrentNumberofStudents=CourseCurrentNumberofStudents+1;

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.